use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class AutoBundleActivity method unBundleItems.
/**
* Removes all automatic bundles from the order and replaces with DiscreteOrderItems.
*
* @param order
*/
private List<DiscreteOrderItem> unBundleItems(Order order) throws PricingException {
List<DiscreteOrderItem> unbundledItems = null;
for (OrderItem orderItem : order.getOrderItems()) {
if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
if (bundleOrderItem.getProductBundle() != null && bundleOrderItem.getProductBundle().getAutoBundle()) {
if (unbundledItems == null) {
unbundledItems = new ArrayList<DiscreteOrderItem>();
}
for (DiscreteOrderItem item : bundleOrderItem.getDiscreteOrderItems()) {
DiscreteOrderItem newOrderItem = (DiscreteOrderItem) item.clone();
newOrderItem.setQuantity(item.getQuantity() * bundleOrderItem.getQuantity());
newOrderItem.setSkuBundleItem(null);
newOrderItem.setBundleOrderItem(null);
newOrderItem.updateSaleAndRetailPrices();
newOrderItem.setOrder(order);
unbundledItems.add(newOrderItem);
}
}
}
}
return unbundledItems;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class AutoBundleActivity method countMaximumApplications.
protected int countMaximumApplications(Order order, SkuBundleItem skuBundleItem, Set<Long> processedBundles) {
int skuMatches = 0;
Long skuId = skuBundleItem.getSku().getId();
for (OrderItem orderItem : order.getOrderItems()) {
if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem item = (DiscreteOrderItem) orderItem;
if (skuId.equals(item.getSku().getId())) {
skuMatches = skuMatches + item.getQuantity();
}
} else if (orderItem instanceof BundleOrderItem) {
BundleOrderItem bundleItem = (BundleOrderItem) orderItem;
if (bundleItem.getProductBundle() != null && bundleItem.getProductBundle().getAutoBundle()) {
if (!processedBundles.contains(bundleItem.getId())) {
for (DiscreteOrderItem discreteItem : bundleItem.getDiscreteOrderItems()) {
if (skuId.equals(discreteItem.getSku().getId())) {
skuMatches = skuMatches + (discreteItem.getQuantity() * bundleItem.getQuantity());
}
}
}
}
}
}
return skuMatches / skuBundleItem.getQuantity();
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemStrategyImpl method verify.
@Override
public CartOperationRequest verify(CartOperationRequest request) throws PricingException {
Order order = request.getOrder();
if (isRemoveEmptyFulfillmentGroups() && order.getFulfillmentGroups() != null) {
ListIterator<FulfillmentGroup> fgIter = order.getFulfillmentGroups().listIterator();
while (fgIter.hasNext()) {
FulfillmentGroup fg = fgIter.next();
if (fg.getFulfillmentGroupItems() == null || fg.getFulfillmentGroupItems().size() == 0) {
fgIter.remove();
fulfillmentGroupService.delete(fg);
}
}
}
Map<Long, Integer> oiQuantityMap = new HashMap<Long, Integer>();
List<OrderItem> expandedOrderItems = new ArrayList<OrderItem>();
for (OrderItem oi : order.getOrderItems()) {
if (oi instanceof BundleOrderItem) {
for (DiscreteOrderItem doi : ((BundleOrderItem) oi).getDiscreteOrderItems()) {
expandedOrderItems.add(doi);
}
} else if (oi instanceof DiscreteOrderItem) {
expandedOrderItems.add(oi);
} else {
expandedOrderItems.add(oi);
}
}
for (OrderItem oi : expandedOrderItems) {
Integer oiQuantity = oiQuantityMap.get(oi.getId());
if (oiQuantity == null) {
oiQuantity = 0;
}
if (oi instanceof DiscreteOrderItem && ((DiscreteOrderItem) oi).getBundleOrderItem() != null) {
oiQuantity += ((DiscreteOrderItem) oi).getBundleOrderItem().getQuantity() * oi.getQuantity();
} else {
oiQuantity += oi.getQuantity();
}
oiQuantityMap.put(oi.getId(), oiQuantity);
}
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
Long oiId = fgi.getOrderItem().getId();
Integer oiQuantity = oiQuantityMap.get(oiId);
if (oiQuantity == null) {
throw new IllegalStateException("Fulfillment group items and discrete order items are not in sync. DiscreteOrderItem id: " + oiId);
}
oiQuantity -= fgi.getQuantity();
oiQuantityMap.put(oiId, oiQuantity);
}
}
for (Entry<Long, Integer> entry : oiQuantityMap.entrySet()) {
if (!entry.getValue().equals(0)) {
throw new IllegalStateException("Not enough fulfillment group items found for DiscreteOrderItem id: " + entry.getKey());
}
}
return request;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class CheckUpdateAvailabilityActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
return context;
}
Sku sku;
Long orderItemId = request.getItemRequest().getOrderItemId();
OrderItem orderItem = orderItemService.readOrderItemById(orderItemId);
if (orderItem instanceof DiscreteOrderItem) {
sku = ((DiscreteOrderItem) orderItem).getSku();
} else if (orderItem instanceof BundleOrderItem) {
sku = ((BundleOrderItem) orderItem).getSku();
} else {
LOG.warn("Could not check availability; did not recognize passed-in item " + orderItem.getClass().getName());
return context;
}
Order order = context.getSeedData().getOrder();
Integer requestedQuantity = request.getItemRequest().getQuantity();
checkSkuAvailability(order, sku, requestedQuantity);
Integer previousQty = orderItem.getQuantity();
for (OrderItem child : orderItem.getChildOrderItems()) {
Sku childSku = ((DiscreteOrderItem) child).getSku();
Integer childQuantity = child.getQuantity();
childQuantity = childQuantity / previousQty;
checkSkuAvailability(order, childSku, childQuantity * requestedQuantity);
}
return context;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class UpdateOrderItemActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
Order order = request.getOrder();
OrderItem orderItem = null;
for (OrderItem oi : order.getOrderItems()) {
if (oi.getId().equals(orderItemRequestDTO.getOrderItemId())) {
orderItem = oi;
}
}
if (orderItem == null || !order.getOrderItems().contains(orderItem)) {
throw new ItemNotFoundException("Order Item (" + orderItemRequestDTO.getOrderItemId() + ") not found in Order (" + order.getId() + ")");
}
OrderItem itemFromOrder = order.getOrderItems().get(order.getOrderItems().indexOf(orderItem));
if (orderItemRequestDTO.getQuantity() >= 0) {
int previousQty = itemFromOrder.getQuantity();
request.setOrderItemQuantityDelta(orderItemRequestDTO.getQuantity() - itemFromOrder.getQuantity());
itemFromOrder.setQuantity(orderItemRequestDTO.getQuantity());
for (OrderItem child : itemFromOrder.getChildOrderItems()) {
int childQuantity = child.getQuantity();
childQuantity = childQuantity / previousQty;
child.setQuantity(childQuantity * orderItemRequestDTO.getQuantity());
}
// Update any additional attributes of the passed in request
if (itemFromOrder instanceof DiscreteOrderItem) {
DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) itemFromOrder;
discreteOrderItem.getAdditionalAttributes().putAll(orderItemRequestDTO.getAdditionalAttributes());
}
request.setOrderItem(itemFromOrder);
}
return context;
}
Aggregations