use of org.broadleafcommerce.core.order.service.call.MergeCartResponse 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.service.call.MergeCartResponse in project BroadleafCommerce by BroadleafCommerce.
the class CartStateRequestProcessor method mergeCart.
/**
* Looks up the anonymous customer and merges that cart with the cart from the given logged in <b>customer</b>. This
* will also remove the customer from session after it has finished since it is no longer needed
*/
public Order mergeCart(Customer customer, WebRequest request) {
Customer anonymousCustomer = customerStateRequestProcessor.getAnonymousCustomer(request);
MergeCartResponse mergeCartResponse;
try {
Order cart = orderService.findCartForCustomer(anonymousCustomer);
mergeCartResponse = mergeCartService.mergeCart(customer, cart);
} catch (PricingException e) {
throw new RuntimeException(e);
} catch (RemoveFromCartException e) {
throw new RuntimeException(e);
}
if (BLCRequestUtils.isOKtoUseSession(request)) {
// The anonymous customer from session is no longer needed; it can be safely removed
request.removeAttribute(CustomerStateRequestProcessor.getAnonymousCustomerSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION);
request.removeAttribute(CustomerStateRequestProcessor.getAnonymousCustomerIdSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION);
request.setAttribute(mergeCartResponseKey, mergeCartResponse, WebRequest.SCOPE_GLOBAL_SESSION);
}
return mergeCartResponse.getOrder();
}
use of org.broadleafcommerce.core.order.service.call.MergeCartResponse in project BroadleafCommerce by BroadleafCommerce.
the class MergeCartProcessorImpl method execute.
@Override
public void execute(WebRequest request, Authentication authResult) {
Customer loggedInCustomer = customerService.readCustomerByUsername(authResult.getName());
Customer anonymousCustomer = customerStateRequestProcessor.getAnonymousCustomer(request);
Order cart = null;
if (anonymousCustomer != null) {
cart = orderService.findCartForCustomer(anonymousCustomer);
}
MergeCartResponse mergeCartResponse;
try {
mergeCartResponse = mergeCartService.mergeCart(loggedInCustomer, cart);
} catch (PricingException e) {
throw new RuntimeException(e);
} catch (RemoveFromCartException e) {
throw new RuntimeException(e);
}
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.setAttribute(mergeCartResponseKey, mergeCartResponse, WebRequest.SCOPE_GLOBAL_SESSION);
}
}
Aggregations