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