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);
}
}
}
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;
}
}
Aggregations