Search in sources :

Example 1 with DiscreteOrderItemRequest

use of org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest in project BroadleafCommerce by BroadleafCommerce.

the class LegacyOrderServiceImpl method createDiscreteOrderItemRequest.

protected DiscreteOrderItemRequest createDiscreteOrderItemRequest(DiscreteOrderItem discreteOrderItem) {
    DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
    itemRequest.setCategory(discreteOrderItem.getCategory());
    itemRequest.setProduct(discreteOrderItem.getProduct());
    itemRequest.setQuantity(discreteOrderItem.getQuantity());
    itemRequest.setSku(discreteOrderItem.getSku());
    if (discreteOrderItem.getPersonalMessage() != null) {
        PersonalMessage personalMessage = orderItemService.createPersonalMessage();
        try {
            BeanUtils.copyProperties(personalMessage, discreteOrderItem.getPersonalMessage());
            personalMessage.setId(null);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        itemRequest.setPersonalMessage(personalMessage);
    }
    return itemRequest;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) PersonalMessage(org.broadleafcommerce.core.order.domain.PersonalMessage) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with DiscreteOrderItemRequest

use of org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest in project BroadleafCommerce by BroadleafCommerce.

the class LegacyOrderServiceImpl method createDiscreteOrderItemRequest.

public DiscreteOrderItemRequest createDiscreteOrderItemRequest(Order order, BundleOrderItem bundleOrderItem, Sku sku, Product product, Category category, Integer quantity, Map<String, String> itemAttributes) {
    DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
    itemRequest.setOrder(order);
    itemRequest.setBundleOrderItem(bundleOrderItem);
    itemRequest.setCategory(category);
    itemRequest.setProduct(product);
    itemRequest.setQuantity(quantity);
    itemRequest.setSku(sku);
    itemRequest.setItemAttributes(itemAttributes);
    return itemRequest;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)

Example 3 with DiscreteOrderItemRequest

use of org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method buildOrderItemFromDTO.

@Override
public OrderItem buildOrderItemFromDTO(Order order, OrderItemRequestDTO orderItemRequestDTO) {
    Sku sku = null;
    if (orderItemRequestDTO.getSkuId() != null) {
        sku = catalogService.findSkuById(orderItemRequestDTO.getSkuId());
    }
    Product product = null;
    if (orderItemRequestDTO.getProductId() != null) {
        product = catalogService.findProductById(orderItemRequestDTO.getProductId());
    }
    Category category = null;
    if (orderItemRequestDTO.getCategoryId() != null) {
        category = catalogService.findCategoryById(orderItemRequestDTO.getCategoryId());
    }
    if (category == null && product != null) {
        category = product.getDefaultCategory();
    }
    OrderItem item;
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequestDTO;
        OrderItemRequest itemRequest = new OrderItemRequest();
        itemRequest.setQuantity(ndr.getQuantity());
        itemRequest.setRetailPriceOverride(ndr.getOverrideRetailPrice());
        itemRequest.setSalePriceOverride(ndr.getOverrideSalePrice());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setItemName(ndr.getItemName());
        itemRequest.setOrder(order);
        item = createOrderItem(itemRequest);
    } else if (product == null || !(product instanceof ProductBundle)) {
        DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
        itemRequest.setCategory(category);
        itemRequest.setProduct(product);
        itemRequest.setSku(sku);
        itemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setOrder(order);
        itemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        itemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createDiscreteOrderItem(itemRequest);
    } else {
        ProductBundleOrderItemRequest bundleItemRequest = new ProductBundleOrderItemRequest();
        bundleItemRequest.setCategory(category);
        bundleItemRequest.setProductBundle((ProductBundle) product);
        bundleItemRequest.setSku(sku);
        bundleItemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        bundleItemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        bundleItemRequest.setName(product.getName());
        bundleItemRequest.setOrder(order);
        bundleItemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        bundleItemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createBundleOrderItem(bundleItemRequest, false);
    }
    if (orderItemRequestDTO.getParentOrderItemId() != null) {
        OrderItem parent = readOrderItemById(orderItemRequestDTO.getParentOrderItemId());
        item.setParentOrderItem(parent);
    }
    if (orderItemRequestDTO.getHasConfigurationError()) {
        item.setHasValidationError(true);
    }
    if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
        ConfigurableOrderItemRequest configRequest = (ConfigurableOrderItemRequest) orderItemRequestDTO;
        if (configRequest.getHasConfigurationError()) {
            item.setHasValidationError(true);
        }
        if (!configRequest.getDiscountsAllowed()) {
            item.setDiscountingAllowed(false);
        }
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) AbstractOrderItemRequest(org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest) GiftWrapOrderItemRequest(org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest) OrderItemRequest(org.broadleafcommerce.core.order.service.call.OrderItemRequest) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) BundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest) Category(org.broadleafcommerce.core.catalog.domain.Category) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) 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) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 4 with DiscreteOrderItemRequest

use of org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest in project BroadleafCommerce by BroadleafCommerce.

the class UpdateProductOptionsOrderItemActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    Order order = request.getOrder();
    if (orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())) != null) {
        DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        orderItemService.updateDiscreteOrderItem(orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())), itemRequest);
    }
    order = orderService.save(order, false);
    request.setOrder(order);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)

Example 5 with DiscreteOrderItemRequest

use of org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest 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

DiscreteOrderItemRequest (org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)6 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)3 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)3 Category (org.broadleafcommerce.core.catalog.domain.Category)2 Product (org.broadleafcommerce.core.catalog.domain.Product)2 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)2 Sku (org.broadleafcommerce.core.catalog.domain.Sku)2 GiftWrapOrderItemRequest (org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SkuBundleItem (org.broadleafcommerce.core.catalog.domain.SkuBundleItem)1 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 Order (org.broadleafcommerce.core.order.domain.Order)1 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)1 PersonalMessage (org.broadleafcommerce.core.order.domain.PersonalMessage)1 AbstractOrderItemRequest (org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest)1 BundleOrderItemRequest (org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest)1 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)1 NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)1 OrderItemRequest (org.broadleafcommerce.core.order.service.call.OrderItemRequest)1 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)1