use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyMergeCartServiceImpl method mergeCart.
@Override
public MergeCartResponse mergeCart(Customer customer, Order anonymousCart, boolean priceOrder) throws PricingException {
MergeCartResponse mergeCartResponse = new MergeCartResponse();
// reconstruct cart items (make sure they are valid)
ReconstructCartResponse reconstructCartResponse = reconstructCart(customer, false);
mergeCartResponse.setRemovedItems(reconstructCartResponse.getRemovedItems());
Order customerCart = reconstructCartResponse.getOrder();
if (anonymousCart != null && customerCart != null && anonymousCart.getId().equals(customerCart.getId())) {
/*
* Set merged to false if the cart ids are equal (cookied customer
* logs in).
*/
mergeCartResponse.setMerged(false);
} else {
/*
* Set the response to merged if the saved cart has any items
* available to merge in.
*/
mergeCartResponse.setMerged(customerCart != null && customerCart.getOrderItems().size() > 0);
}
// add anonymous cart items (make sure they are valid)
if (anonymousCart != null && (customerCart == null || !customerCart.getId().equals(anonymousCart.getId()))) {
if (anonymousCart != null && anonymousCart.getOrderItems() != null && !anonymousCart.getOrderItems().isEmpty()) {
if (customerCart == null) {
customerCart = orderService.createNewCartForCustomer(customer);
}
Map<OrderItem, OrderItem> oldNewItemMap = new HashMap<OrderItem, OrderItem>();
customerCart = mergeRegularOrderItems(anonymousCart, mergeCartResponse, customerCart, oldNewItemMap);
customerCart = mergeOfferCodes(anonymousCart, customerCart);
customerCart = removeExpiredGiftWrapOrderItems(mergeCartResponse, customerCart, oldNewItemMap);
customerCart = mergeGiftWrapOrderItems(mergeCartResponse, customerCart, oldNewItemMap);
orderService.cancelOrder(anonymousCart);
}
}
// copy the customer's email to this order, overriding any previously set email
if (customerCart != null && StringUtils.isNotBlank(customer.getEmailAddress())) {
customerCart.setEmailAddress(customer.getEmailAddress());
customerCart = orderService.save(customerCart, priceOrder);
}
mergeCartResponse.setOrder(customerCart);
return mergeCartResponse;
}
use of org.broadleafcommerce.core.order.domain.OrderItem 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;
}
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method createDefaultFulfillmentGroup.
@Override
public FulfillmentGroup createDefaultFulfillmentGroup(Order order, Address address) {
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
if (fulfillmentGroup.isPrimary()) {
return fulfillmentGroup;
}
}
FulfillmentGroup newFg = fulfillmentGroupService.createEmptyFulfillmentGroup();
newFg.setOrder(order);
newFg.setPrimary(true);
newFg.setAddress(address);
for (OrderItem orderItem : order.getOrderItems()) {
newFg.addFulfillmentGroupItem(createFulfillmentGroupItemFromOrderItem(orderItem, newFg, orderItem.getQuantity()));
}
return newFg;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method removeItemFromOrder.
@Override
public Order removeItemFromOrder(Order order, OrderItem item, boolean priceOrder) throws PricingException {
fulfillmentGroupService.removeOrderItemFromFullfillmentGroups(order, item);
OrderItem itemFromOrder = order.getOrderItems().remove(order.getOrderItems().indexOf(item));
itemFromOrder.setOrder(null);
orderItemService.delete(itemFromOrder);
order = updateOrder(order, priceOrder);
return order;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderServiceImpl method addAllItemsFromNamedOrder.
@Override
@Transactional("blTransactionManager")
public Order addAllItemsFromNamedOrder(Order namedOrder, boolean priceOrder) throws RemoveFromCartException, AddToCartException {
Order cartOrder = orderDao.readCartForCustomer(namedOrder.getCustomer());
if (cartOrder == null) {
cartOrder = createNewCartForCustomer(namedOrder.getCustomer());
}
List<OrderItem> items = new ArrayList<OrderItem>(namedOrder.getOrderItems());
// Remove any order items that are children
CollectionUtils.filter(items, new TypedPredicate<OrderItem>() {
@Override
public boolean eval(OrderItem orderItem) {
return orderItem.getParentOrderItem() == null;
}
});
for (OrderItem item : items) {
OrderItemRequestDTO orderItemRequest = orderItemService.buildOrderItemRequestDTOFromOrderItem(item);
cartOrder = addItem(cartOrder.getId(), orderItemRequest, priceOrder);
if (moveNamedOrderItems) {
removeItem(namedOrder.getId(), item.getId(), false);
}
}
if (deleteEmptyNamedOrders) {
cancelOrder(namedOrder);
}
return cartOrder;
}
Aggregations