use of org.broadleafcommerce.core.order.service.call.OrderItemRequest 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;
}
Aggregations