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