Search in sources :

Example 6 with OrderItemAttribute

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

the class OrderItemServiceImpl method populateProductOptionAttributes.

protected void populateProductOptionAttributes(OrderItem item, Map<String, String> attributes) {
    if (attributes != null && attributes.size() > 0) {
        Map<String, OrderItemAttribute> orderItemAttributes = item.getOrderItemAttributes();
        if (item.getOrderItemAttributes() == null) {
            orderItemAttributes = new HashMap<String, OrderItemAttribute>();
            item.setOrderItemAttributes(orderItemAttributes);
        }
        for (String key : attributes.keySet()) {
            String value = attributes.get(key);
            OrderItemAttribute attribute = new OrderItemAttributeImpl();
            attribute.setName(key);
            attribute.setValue(value);
            attribute.setOrderItem(item);
            orderItemAttributes.put(key, attribute);
        }
    }
}
Also used : OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)

Example 7 with OrderItemAttribute

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

the class LegacyOrderServiceImpl method addOrUpdateOrderItemAttributes.

/**
 * Adds the passed in name/value pair to the order-item.    If the
 * attribute already exists, then it is updated with the new value.
 * <p/>
 * If the value passed in is null and the attribute exists, it is removed
 * from the order item.
 *
 * @param order
 * @param item
 * @param attributeValues
 * @param priceOrder
 * @return
 */
@Override
public Order addOrUpdateOrderItemAttributes(Order order, OrderItem item, Map<String, String> attributeValues, 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));
    Map<String, OrderItemAttribute> orderItemAttributes = itemFromOrder.getOrderItemAttributes();
    if (orderItemAttributes == null) {
        orderItemAttributes = new HashMap<String, OrderItemAttribute>();
        itemFromOrder.setOrderItemAttributes(orderItemAttributes);
    }
    boolean changeMade = false;
    for (String attributeName : attributeValues.keySet()) {
        String attributeValue = attributeValues.get(attributeName);
        OrderItemAttribute attribute = orderItemAttributes.get(attributeName);
        if (attribute != null && attribute.getValue().equals(attributeValue)) {
            // no change made.
            continue;
        } else {
            changeMade = true;
            if (attribute == null) {
                attribute = new OrderItemAttributeImpl();
                attribute.setOrderItem(itemFromOrder);
                attribute.setName(attributeName);
                attribute.setValue(attributeValue);
            } else if (attributeValue == null) {
                orderItemAttributes.remove(attributeValue);
            } else {
                attribute.setValue(attributeValue);
            }
        }
    }
    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) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

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