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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations