use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.
the class ValidateUpdateRequestActivity 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 tried to update an item to a negative quantity
if (orderItemRequestDTO.getQuantity() < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
}
// 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 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) {
throw new IllegalArgumentException("Cannot update an item that is part of a bundle");
}
}
return context;
}
use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.
the class UpdateProductOptionsOrderItemActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
Order order = request.getOrder();
if (orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())) != null) {
DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
orderItemService.updateDiscreteOrderItem(orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())), itemRequest);
}
order = orderService.save(order, false);
request.setOrder(order);
return context;
}
use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.
the class ValidateAddRequestActivity method validate.
protected ProcessContext<CartOperationRequest> validate(ProcessContext<CartOperationRequest> context) {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
Integer orderItemQuantity = orderItemRequestDTO.getQuantity();
if (!hasQuantity(orderItemQuantity)) {
context.stopProcess();
} else if (orderItemQuantity < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
} else if (request.getOrder() == null) {
throw new IllegalArgumentException("Order is required when adding item to order");
} else {
Product product = determineProduct(orderItemRequestDTO);
Sku sku;
try {
sku = determineSku(product, orderItemRequestDTO.getSkuId(), orderItemRequestDTO.getItemAttributes(), (ActivityMessages) context);
} catch (RequiredAttributeNotProvidedException e) {
if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
// Mark the request as a configuration error and proceed with the add.
orderItemRequestDTO.setHasConfigurationError(Boolean.TRUE);
return context;
}
throw e;
}
addSkuToCart(sku, orderItemRequestDTO, product, request);
if (!hasSameCurrency(orderItemRequestDTO, request, sku)) {
throw new IllegalArgumentException("Cannot have items with differing currencies in one cart");
}
validateIfParentOrderItemExists(orderItemRequestDTO);
}
return context;
}
use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.
the class UpdateFulfillmentGroupItemActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
request = fgItemStrategy.onItemUpdated(request);
context.setSeedData(request);
return context;
}
use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest 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