Search in sources :

Example 1 with RequiredAttributeNotProvidedException

use of org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException in project BroadleafCommerce by BroadleafCommerce.

the class CheckoutServiceImpl method performCheckout.

@Override
public CheckoutResponse performCheckout(Order order) throws CheckoutException {
    // Immediately fail if another thread is currently attempting to check out the order
    Object lockObject = putLock(order.getId());
    if (lockObject != null) {
        throw new CheckoutException("This order is already in the process of being submitted, unable to checkout order -- id: " + order.getId(), new CheckoutSeed(order, new HashMap<String, Object>()));
    }
    // Immediately fail if this order has already been checked out previously
    if (hasOrderBeenCompleted(order)) {
        throw new CheckoutException("This order has already been submitted or cancelled, unable to checkout order -- id: " + order.getId(), new CheckoutSeed(order, new HashMap<String, Object>()));
    }
    CheckoutSeed seed = null;
    try {
        // Do a final save of the order before going through with the checkout workflow
        order = orderService.save(order, false);
        seed = new CheckoutSeed(order, new HashMap<String, Object>());
        ProcessContext<CheckoutSeed> context = checkoutWorkflow.doActivities(seed);
        // We need to pull the order off the seed and save it here in case any activity modified the order.
        order = orderService.save(seed.getOrder(), false);
        order.getOrderMessages().addAll(((ActivityMessages) context).getActivityMessages());
        seed.setOrder(order);
        return seed;
    } catch (PricingException e) {
        throw new CheckoutException("Unable to checkout order -- id: " + order.getId(), e, seed);
    } catch (WorkflowException e) {
        throw new CheckoutException("Unable to checkout order -- id: " + order.getId(), e.getRootCause(), seed);
    } catch (RequiredAttributeNotProvidedException e) {
        throw new CheckoutException("Unable to checkout order -- id: " + order.getId(), e.getCause(), seed);
    } finally {
        // The order has completed processing, remove the order from the processing map
        removeLock(order.getId());
    }
}
Also used : PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) RequiredAttributeNotProvidedException(org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException) CheckoutSeed(org.broadleafcommerce.core.checkout.service.workflow.CheckoutSeed) CheckoutException(org.broadleafcommerce.core.checkout.service.exception.CheckoutException)

Example 2 with RequiredAttributeNotProvidedException

use of org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException 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;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) ActivityMessages(org.broadleafcommerce.core.workflow.ActivityMessages) Product(org.broadleafcommerce.core.catalog.domain.Product) RequiredAttributeNotProvidedException(org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Example 3 with RequiredAttributeNotProvidedException

use of org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException 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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) ProductOption(org.broadleafcommerce.core.catalog.domain.ProductOption) ActivityMessages(org.broadleafcommerce.core.workflow.ActivityMessages) OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) ProductOptionXref(org.broadleafcommerce.core.catalog.domain.ProductOptionXref) Product(org.broadleafcommerce.core.catalog.domain.Product) RequiredAttributeNotProvidedException(org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException)

Aggregations

RequiredAttributeNotProvidedException (org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException)3 Product (org.broadleafcommerce.core.catalog.domain.Product)2 ActivityMessages (org.broadleafcommerce.core.workflow.ActivityMessages)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ProductOption (org.broadleafcommerce.core.catalog.domain.ProductOption)1 ProductOptionXref (org.broadleafcommerce.core.catalog.domain.ProductOptionXref)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 CheckoutException (org.broadleafcommerce.core.checkout.service.exception.CheckoutException)1 CheckoutSeed (org.broadleafcommerce.core.checkout.service.workflow.CheckoutSeed)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 Order (org.broadleafcommerce.core.order.domain.Order)1 OrderItemAttribute (org.broadleafcommerce.core.order.domain.OrderItemAttribute)1 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)1 NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)1 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)1 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)1 PricingException (org.broadleafcommerce.core.pricing.service.exception.PricingException)1 WorkflowException (org.broadleafcommerce.core.workflow.WorkflowException)1