Search in sources :

Example 1 with OrderItemAttribute

use of org.broadleafcommerce.core.order.domain.OrderItemAttribute in project BroadleafCommerce by BroadleafCommerce.

the class LegacyOrderServiceImpl method removeOrderItemAttribute.

@Override
public Order removeOrderItemAttribute(Order order, OrderItem item, String attributeName, boolean priceOrder) throws ItemNotFoundException, PricingException {
    if (!order.getOrderItems().contains(item)) {
        throw new ItemNotFoundException("Order Item (" + item.getId() + ") not found in Order (" + order.getId() + ")");
    }
    OrderItem itemFromOrder = order.getOrderItems().get(order.getOrderItems().indexOf(item));
    boolean changeMade = false;
    Map<String, OrderItemAttribute> orderItemAttributes = itemFromOrder.getOrderItemAttributes();
    if (orderItemAttributes != null) {
        if (orderItemAttributes.containsKey(attributeName)) {
            changeMade = true;
            orderItemAttributes.remove(attributeName);
        }
    }
    if (changeMade) {
        return updateOrder(order, priceOrder);
    } else {
        return order;
    }
}
Also used : OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Example 2 with OrderItemAttribute

use of org.broadleafcommerce.core.order.domain.OrderItemAttribute in project BroadleafCommerce by BroadleafCommerce.

the class i18nUpdateCartServiceExtensionHandler method translateOrderItem.

protected void translateOrderItem(OrderItem orderItem, Sku sku) {
    if (sku != null) {
        orderItem.setName(sku.getName());
        if (sku.getProductOptionValues() != null) {
            for (ProductOptionValue optionValue : sku.getProductOptionValues()) {
                String key = optionValue.getProductOption().getAttributeName();
                OrderItemAttribute attr = orderItem.getOrderItemAttributes().get(key);
                if (attr != null) {
                    attr.setValue(optionValue.getAttributeValue());
                } else {
                    OrderItemAttribute attribute = new OrderItemAttributeImpl();
                    attribute.setName(key);
                    attribute.setValue(optionValue.getAttributeValue());
                    attribute.setOrderItem(orderItem);
                    orderItem.getOrderItemAttributes().put(key, attribute);
                }
            }
        }
    }
}
Also used : ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)

Example 3 with OrderItemAttribute

use of org.broadleafcommerce.core.order.domain.OrderItemAttribute 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)

Example 4 with OrderItemAttribute

use of org.broadleafcommerce.core.order.domain.OrderItemAttribute in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method createOrderItem.

@Override
public OrderItem createOrderItem(final OrderItemRequest itemRequest) {
    final OrderItem item = orderItemDao.create(OrderItemType.BASIC);
    item.setName(itemRequest.getItemName());
    item.setQuantity(itemRequest.getQuantity());
    item.setOrder(itemRequest.getOrder());
    if (itemRequest.getSalePriceOverride() != null) {
        item.setSalePriceOverride(Boolean.TRUE);
        item.setSalePrice(itemRequest.getSalePriceOverride());
    }
    if (itemRequest.getRetailPriceOverride() != null) {
        item.setRetailPriceOverride(Boolean.TRUE);
        item.setRetailPrice(itemRequest.getRetailPriceOverride());
    }
    if (MapUtils.isNotEmpty(itemRequest.getItemAttributes())) {
        Map<String, OrderItemAttribute> attributeMap = item.getOrderItemAttributes();
        if (attributeMap == null) {
            attributeMap = new HashMap<String, OrderItemAttribute>();
            item.setOrderItemAttributes(attributeMap);
        }
        for (Entry<String, String> entry : itemRequest.getItemAttributes().entrySet()) {
            OrderItemAttribute orderItemAttribute = new OrderItemAttributeImpl();
            orderItemAttribute.setName(entry.getKey());
            orderItemAttribute.setValue(entry.getValue());
            orderItemAttribute.setOrderItem(item);
            attributeMap.put(entry.getKey(), orderItemAttribute);
        }
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)

Example 5 with OrderItemAttribute

use of org.broadleafcommerce.core.order.domain.OrderItemAttribute in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method buildOrderItemRequestDTOFromOrderItem.

@Override
public OrderItemRequestDTO buildOrderItemRequestDTOFromOrderItem(OrderItem item) {
    OrderItemRequestDTO orderItemRequest;
    if (item instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) item;
        orderItemRequest = new OrderItemRequestDTO();
        if (doi.getCategory() != null) {
            orderItemRequest.setCategoryId(doi.getCategory().getId());
        }
        if (doi.getProduct() != null) {
            orderItemRequest.setProductId(doi.getProduct().getId());
        }
        if (doi.getSku() != null) {
            orderItemRequest.setSkuId(doi.getSku().getId());
        }
        if (doi.getAdditionalAttributes() != null) {
            for (Entry<String, String> entry : doi.getAdditionalAttributes().entrySet()) {
                orderItemRequest.getAdditionalAttributes().put(entry.getKey(), entry.getValue());
            }
        }
    } else {
        orderItemRequest = new NonDiscreteOrderItemRequestDTO();
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequest;
        ndr.setItemName(item.getName());
        ndr.setOverrideRetailPrice(item.getRetailPrice());
        ndr.setOverrideSalePrice(item.getSalePrice());
    }
    orderItemRequest.setQuantity(item.getQuantity());
    if (item.getOrderItemAttributes() != null) {
        for (Entry<String, OrderItemAttribute> entry : item.getOrderItemAttributes().entrySet()) {
            orderItemRequest.getItemAttributes().put(entry.getKey(), entry.getValue().getValue());
        }
    }
    if (CollectionUtils.isNotEmpty(item.getChildOrderItems())) {
        for (OrderItem childItem : item.getChildOrderItems()) {
            orderItemRequest.getChildOrderItems().add(buildOrderItemRequestDTOFromOrderItem(childItem));
        }
    }
    return orderItemRequest;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Aggregations

OrderItemAttribute (org.broadleafcommerce.core.order.domain.OrderItemAttribute)7 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)4 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)4 OrderItemAttributeImpl (org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)4 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)2 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)2 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductOption (org.broadleafcommerce.core.catalog.domain.ProductOption)1 ProductOptionValue (org.broadleafcommerce.core.catalog.domain.ProductOptionValue)1 ProductOptionXref (org.broadleafcommerce.core.catalog.domain.ProductOptionXref)1 Order (org.broadleafcommerce.core.order.domain.Order)1 NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)1 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)1 RequiredAttributeNotProvidedException (org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException)1 ActivityMessages (org.broadleafcommerce.core.workflow.ActivityMessages)1