use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutTest method addSampleItemToOrder.
private void addSampleItemToOrder(Order order, FulfillmentGroup group) {
DiscreteOrderItem item = new DiscreteOrderItemImpl();
item.setOrder(order);
item.setQuantity(1);
Sku newSku = new SkuImpl();
newSku.setName("Under Armor T-Shirt -- Red");
newSku.setRetailPrice(new Money(14.99));
newSku.setActiveStartDate(SystemTime.asDate());
newSku.setDiscountable(false);
newSku = catalogService.saveSku(newSku);
item.setSku(newSku);
item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
List<OrderItem> items = new ArrayList<>();
items.add(item);
order.setOrderItems(items);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item);
fgItem.setQuantity(1);
// fgItem.setPrice(new Money(0D));
group.addFulfillmentGroupItem(fgItem);
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderMultishipOptionServiceImpl method getOrGenerateOrderMultishipOptions.
@Override
public List<OrderMultishipOption> getOrGenerateOrderMultishipOptions(Order order) {
List<OrderMultishipOption> orderMultishipOptions = findOrderMultishipOptions(order.getId());
if (orderMultishipOptions == null || orderMultishipOptions.size() == 0) {
orderMultishipOptions = generateOrderMultishipOptions(order);
}
// Create a map representing the current discrete order item counts for the order
Map<Long, Integer> orderDiscreteOrderItemCounts = new HashMap<Long, Integer>();
for (DiscreteOrderItem item : order.getDiscreteOrderItems()) {
orderDiscreteOrderItemCounts.put(item.getId(), item.getQuantity());
}
List<OrderMultishipOption> optionsToRemove = new ArrayList<OrderMultishipOption>();
for (OrderMultishipOption option : orderMultishipOptions) {
Integer count = orderDiscreteOrderItemCounts.get(option.getOrderItem().getId());
if (count == null || count == 0) {
optionsToRemove.add(option);
} else {
count--;
orderDiscreteOrderItemCounts.put(option.getOrderItem().getId(), count);
}
}
for (Entry<Long, Integer> entry : orderDiscreteOrderItemCounts.entrySet()) {
DiscreteOrderItem item = (DiscreteOrderItem) orderItemService.readOrderItemById(entry.getKey());
orderMultishipOptions.addAll(createPopulatedOrderMultishipOption(order, item, entry.getValue()));
}
orderMultishipOptions.removeAll(optionsToRemove);
orderMultishipOptionDao.deleteAll(optionsToRemove);
return orderMultishipOptions;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem 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.DiscreteOrderItem 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.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method bundleItemMatches.
protected boolean bundleItemMatches(BundleOrderItem item1, BundleOrderItem item2) {
if (item1.getSku() != null && item2.getSku() != null) {
return item1.getSku().getId().equals(item2.getSku().getId());
}
// Otherwise, scan the items.
HashMap<Long, Integer> skuMap = new HashMap<Long, Integer>();
for (DiscreteOrderItem item : item1.getDiscreteOrderItems()) {
if (skuMap.get(item.getSku().getId()) == null) {
skuMap.put(item.getSku().getId(), Integer.valueOf(item.getQuantity()));
} else {
Integer qty = skuMap.get(item.getSku().getId());
skuMap.put(item.getSku().getId(), Integer.valueOf(qty + item.getQuantity()));
}
}
// Now consume the quantities in the map
for (DiscreteOrderItem item : item2.getDiscreteOrderItems()) {
if (skuMap.containsKey(item.getSku().getId())) {
Integer qty = skuMap.get(item.getSku().getId());
Integer newQty = Integer.valueOf(qty - item.getQuantity());
if (newQty.intValue() == 0) {
skuMap.remove(item.getSku().getId());
} else if (newQty.intValue() > 0) {
skuMap.put(item.getSku().getId(), newQty);
} else {
return false;
}
} else {
return false;
}
}
return skuMap.isEmpty();
}
Aggregations