use of org.broadleafcommerce.core.workflow.ActivityMessages 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.workflow.ActivityMessages in project BroadleafCommerce by BroadleafCommerce.
the class ValidateProductOptionsActivity method execute.
@Override
public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context) throws Exception {
if (!useSku) {
Order order = context.getSeedData().getOrder();
List<DiscreteOrderItem> orderItems = getOrderItems(order);
for (DiscreteOrderItem discreteOI : orderItems) {
Map<String, OrderItemAttribute> attributeValues = discreteOI.getOrderItemAttributes();
Product product = discreteOI.getProduct();
if (product != null) {
for (ProductOptionXref productOptionXref : ListUtils.emptyIfNull(product.getProductOptionXrefs())) {
ProductOption productOption = productOptionXref.getProductOption();
String attributeName = productOption.getAttributeName();
OrderItemAttribute attribute = attributeValues.get(attributeName);
String attributeValue = (attribute != null) ? attribute.getValue() : null;
boolean isRequired = productOption.getRequired();
boolean hasStrategy = productOptionValidationService.hasProductOptionValidationStrategy(productOption);
boolean isAddOrNoneType = productOptionValidationService.isAddOrNoneType(productOption);
boolean isSubmitType = productOptionValidationService.isSubmitType(productOption);
if (isMissingRequiredAttribute(isRequired, hasStrategy, isAddOrNoneType, isSubmitType, attributeValue)) {
String message = "Unable to validate cart, product (" + product.getId() + ") required" + " attribute was not provided: " + attributeName;
throw new RequiredAttributeNotProvidedException(message, attributeName, String.valueOf(product.getId()));
}
boolean hasValidationType = productOption.getProductOptionValidationType() != null;
if (shouldValidateWithException(hasValidationType, hasStrategy, isAddOrNoneType, isSubmitType)) {
productOptionValidationService.validate(productOption, attributeValue);
}
if (hasStrategy && !(isAddOrNoneType || isSubmitType)) {
// we need to validate however, we will not error out
ActivityMessages messages = (ActivityMessages) context;
productOptionValidationService.validateWithoutException(productOption, attributeValue, messages);
}
}
}
}
}
return context;
}
Aggregations