use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderServiceImpl method removeItem.
@Override
@Transactional(value = "blTransactionManager", rollbackFor = { RemoveFromCartException.class })
public Order removeItem(Long orderId, Long orderItemId, boolean priceOrder) throws RemoveFromCartException {
preValidateCartOperation(findOrderById(orderId));
try {
OrderItem oi = orderItemService.readOrderItemById(orderItemId);
if (oi == null) {
throw new WorkflowException(new ItemNotFoundException());
}
List<Long> childrenToRemove = new ArrayList<Long>();
if (oi instanceof BundleOrderItem) {
List<DiscreteOrderItem> bundledItems = ((BundleOrderItem) oi).getDiscreteOrderItems();
for (DiscreteOrderItem doi : bundledItems) {
findAllChildrenToRemove(childrenToRemove, doi);
}
} else {
findAllChildrenToRemove(childrenToRemove, oi);
}
for (Long childToRemove : childrenToRemove) {
removeItemInternal(orderId, childToRemove, false);
}
return removeItemInternal(orderId, orderItemId, priceOrder);
} catch (WorkflowException e) {
throw new RemoveFromCartException("Could not remove from cart", getCartOperationExceptionRootCause(e));
}
}
use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method reconstructCart.
@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException {
ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
Order customerCart = orderService.findCartForCustomer(customer);
if (customerCart != null) {
List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
for (OrderItem orderItem : customerCart.getOrderItems()) {
if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
if (discreteOrderItem.getSku().getActiveStartDate() != null) {
if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
itemsToRemove.add(orderItem);
}
} else {
if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
itemsToRemove.add(orderItem);
}
}
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
boolean removeBundle = false;
for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
if (discreteOrderItem.getSku().getActiveStartDate() != null) {
if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
/*
* Bundle has an inactive item in it -- remove the
* whole bundle
*/
removeBundle = true;
break;
}
} else {
if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
removeBundle = true;
break;
}
}
}
if (removeBundle) {
itemsToRemove.add(orderItem);
}
}
}
// Remove any giftwrap items who have one or more wrapped item members that have been removed
for (OrderItem orderItem : customerCart.getOrderItems()) {
if (orderItem instanceof GiftWrapOrderItem) {
for (OrderItem wrappedItem : ((GiftWrapOrderItem) orderItem).getWrappedItems()) {
if (itemsToRemove.contains(wrappedItem)) {
itemsToRemove.add(orderItem);
break;
}
}
}
}
for (OrderItem item : itemsToRemove) {
removeItemFromOrder(customerCart, item, priceOrder);
}
reconstructCartResponse.setRemovedItems(itemsToRemove);
}
reconstructCartResponse.setOrder(customerCart);
return reconstructCartResponse;
}
use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method addBundleItemToOrder.
@Override
public OrderItem addBundleItemToOrder(Order order, BundleOrderItemRequest itemRequest, boolean priceOrder) throws PricingException {
itemRequest.setOrder(order);
BundleOrderItem item = orderItemService.createBundleOrderItem(itemRequest);
return addOrderItemToOrder(order, item, priceOrder);
}
use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method addItemToOrder.
@Override
public Order addItemToOrder(Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws PricingException {
if (orderItemRequestDTO.getQuantity() == null || orderItemRequestDTO.getQuantity() == 0) {
LOG.debug("Not adding item to order because quantity is zero.");
return null;
}
if (orderItemRequestDTO.getQuantity() < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
}
Order order = validateOrder(orderId);
Product product = validateProduct(orderItemRequestDTO.getProductId());
Sku sku = determineSku(product, orderItemRequestDTO.getSkuId(), orderItemRequestDTO.getItemAttributes());
if (sku == null) {
return null;
}
Category category = determineCategory(product, orderItemRequestDTO.getCategoryId());
if (product == null || !(product instanceof ProductBundle)) {
DiscreteOrderItem item = orderItemService.createDiscreteOrderItem(createDiscreteOrderItemRequest(order, null, sku, product, category, orderItemRequestDTO.getQuantity(), orderItemRequestDTO.getItemAttributes()));
item.setOrder(order);
List<OrderItem> orderItems = order.getOrderItems();
orderItems.add(item);
return updateOrder(order, priceOrder);
} else {
ProductBundle bundle = (ProductBundle) product;
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItemDao.create(OrderItemType.BUNDLE);
bundleOrderItem.setQuantity(orderItemRequestDTO.getQuantity());
bundleOrderItem.setCategory(category);
bundleOrderItem.setSku(sku);
bundleOrderItem.setName(product.getName());
bundleOrderItem.setProductBundle(bundle);
bundleOrderItem.setOrder(order);
for (SkuBundleItem skuBundleItem : bundle.getSkuBundleItems()) {
Product bundleProduct = skuBundleItem.getBundle();
Sku bundleSku = skuBundleItem.getSku();
Category bundleCategory = determineCategory(bundleProduct, orderItemRequestDTO.getCategoryId());
DiscreteOrderItem bundleDiscreteItem = orderItemService.createDiscreteOrderItem(createDiscreteOrderItemRequest(null, bundleOrderItem, bundleSku, bundleProduct, bundleCategory, skuBundleItem.getQuantity(), orderItemRequestDTO.getItemAttributes()));
bundleDiscreteItem.setBundleOrderItem(bundleOrderItem);
bundleDiscreteItem.setSkuBundleItem(skuBundleItem);
bundleOrderItem.getDiscreteOrderItems().add(bundleDiscreteItem);
}
List<OrderItem> orderItems = order.getOrderItems();
orderItems.add(bundleOrderItem);
return updateOrder(order, priceOrder);
}
}
use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemStrategyImpl method onItemUpdated.
@Override
public CartOperationRequest onItemUpdated(CartOperationRequest request) throws PricingException {
Order order = request.getOrder();
OrderItem orderItem = request.getOrderItem();
Integer orderItemQuantityDelta = request.getOrderItemQuantityDelta();
if (orderItemQuantityDelta == 0) {
// If the quantity didn't change, nothing needs to happen
return request;
} else {
List<FulfillmentGroupItem> fgisToDelete = new ArrayList<FulfillmentGroupItem>();
if (orderItem instanceof BundleOrderItem) {
List<OrderItem> itemsToUpdate = new ArrayList<OrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
for (OrderItem oi : itemsToUpdate) {
int quantityPer = oi.getQuantity();
fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
}
} else {
fgisToDelete.addAll(updateItemQuantity(order, orderItem, orderItemQuantityDelta));
List<OrderItem> itemsToUpdate = new ArrayList<>(orderItem.getChildOrderItems());
for (OrderItem oi : itemsToUpdate) {
int quantityPer = oi.getQuantity() / orderItem.getQuantity();
fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
}
}
request.setFgisToDelete(fgisToDelete);
}
return request;
}
Aggregations