use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method updateItemQuantity.
@Override
public void updateItemQuantity(Order order, OrderItemRequestDTO orderItemRequestDTO) throws ItemNotFoundException, PricingException {
OrderItem orderItem = null;
for (DiscreteOrderItem doi : order.getDiscreteOrderItems()) {
if (doi.getId().equals(orderItemRequestDTO.getOrderItemId())) {
orderItem = doi;
}
}
orderItem.setQuantity(orderItemRequestDTO.getQuantity());
updateItemQuantity(order, orderItem, true);
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem 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.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class ValidateUpdateProductOptionsRequestActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
// Throw an exception if the user did not specify an orderItemId
if (orderItemRequestDTO.getOrderItemId() == null) {
throw new IllegalArgumentException("OrderItemId must be specified to locate the order item");
}
// Throw an exception if the user did not specify an order to add the item to
if (request.getOrder() == null) {
throw new IllegalArgumentException("Order is required when updating items in the order");
}
// Throw an exception if the user is trying to update an order item that is part of a bundle
OrderItem orderItem = orderItemService.readOrderItemById(orderItemRequestDTO.getOrderItemId());
if (orderItem != null && orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
if (doi.getBundleOrderItem() != null) {
// then its ok , since we are just updating the product options
}
}
return context;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemStrategyImpl method onItemAdded.
@Override
public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
Order order = request.getOrder();
OrderItem orderItem = request.getOrderItem();
Map<FulfillmentType, FulfillmentGroup> fulfillmentGroups = new HashMap<FulfillmentType, FulfillmentGroup>();
FulfillmentGroup nullFulfillmentTypeGroup = null;
// We'll use the first of each type that we find. Implementors can choose to move groups / items around later.
if (order.getFulfillmentGroups() != null) {
for (FulfillmentGroup group : order.getFulfillmentGroups()) {
if (group.getType() == null) {
if (nullFulfillmentTypeGroup == null) {
nullFulfillmentTypeGroup = group;
}
} else {
if (fulfillmentGroups.get(group.getType()) == null) {
fulfillmentGroups.put(group.getType(), group);
}
}
}
}
if (orderItem instanceof BundleOrderItem) {
// We only care about the discrete order items
List<DiscreteOrderItem> itemsToAdd = new ArrayList<DiscreteOrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
for (DiscreteOrderItem doi : itemsToAdd) {
FulfillmentGroup fulfillmentGroup = null;
FulfillmentType type = resolveFulfillmentType(doi);
if (type == null) {
// Use the fulfillment group with a null type
fulfillmentGroup = nullFulfillmentTypeGroup;
} else {
if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
// This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
// However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
type = FulfillmentType.PHYSICAL_SHIP;
}
// Use the fulfillment group with the specified type
fulfillmentGroup = fulfillmentGroups.get(type);
}
// If the null type or specified type, above were null, then we need to create a new fulfillment group
boolean createdFulfillmentGroup = false;
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
// Set the type
fulfillmentGroup.setType(type);
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
createdFulfillmentGroup = true;
}
fulfillmentGroup = addItemToFulfillmentGroup(order, doi, doi.getQuantity() * orderItem.getQuantity(), fulfillmentGroup);
order = fulfillmentGroup.getOrder();
// of fulfillment groups
if (createdFulfillmentGroup) {
if (type == null) {
nullFulfillmentTypeGroup = fulfillmentGroup;
} else {
fulfillmentGroups.put(type, fulfillmentGroup);
}
}
}
} else if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
FulfillmentGroup fulfillmentGroup = null;
FulfillmentType type = resolveFulfillmentType(doi);
if (type == null) {
// Use the fulfillment group with a null type
fulfillmentGroup = nullFulfillmentTypeGroup;
} else {
if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
// This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
// However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
type = FulfillmentType.PHYSICAL_SHIP;
}
// Use the fulfillment group with the specified type
fulfillmentGroup = fulfillmentGroups.get(type);
}
// If the null type or specified type, above were null, then we need to create a new fulfillment group
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
// Set the type
fulfillmentGroup.setType(type);
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
}
fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
order = fulfillmentGroup.getOrder();
} else {
FulfillmentGroup fulfillmentGroup = nullFulfillmentTypeGroup;
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
}
fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
}
return request;
}
use of org.broadleafcommerce.core.order.domain.DiscreteOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class ValidateRemoveRequestActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
// Throw an exception if the user did not specify an orderItemId
if (orderItemRequestDTO.getOrderItemId() == null) {
throw new IllegalArgumentException("OrderItemId must be specified when removing from order");
}
// Throw an exception if the user did not specify an order to add the item to
if (request.getOrder() == null) {
throw new IllegalArgumentException("Order is required when updating item quantities");
}
// Throw an exception if the user is trying to remove an order item that is part of a bundle
OrderItem orderItem = null;
for (OrderItem oi : request.getOrder().getOrderItems()) {
if (oi.getId().equals(orderItemRequestDTO.getOrderItemId())) {
orderItem = oi;
}
}
if (orderItem == null) {
throw new IllegalArgumentException("Could not find order item to remove");
}
if (orderItem != null && orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
if (doi.getBundleOrderItem() != null) {
throw new IllegalArgumentException("Cannot remove an item that is part of a bundle");
}
}
request.setOrderItem(orderItem);
return context;
}
Aggregations