Search in sources :

Example 1 with OrderItemAttributeImpl

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);
                }
            }
        }
    }
}
Also used : ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)

Example 2 with OrderItemAttributeImpl

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;
}
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 3 with OrderItemAttributeImpl

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);
        }
    }
}
Also used : OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)

Example 4 with OrderItemAttributeImpl

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;
    }
}
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)4 OrderItemAttributeImpl (org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl)4 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)2 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)2 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)2 ProductOptionValue (org.broadleafcommerce.core.catalog.domain.ProductOptionValue)1 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)1