use of org.broadleafcommerce.profile.core.domain.Customer 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.profile.core.domain.Customer 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);
}
}
use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.
the class OrderStateAOP method processOrderRetrieval.
public Object processOrderRetrieval(ProceedingJoinPoint call) throws Throwable {
Object returnValue;
/*
* we retrieve the OrderState instance directly from the application
* context, as this bean has a request scope.
*/
OrderState orderState = (OrderState) applicationContext.getBean("blOrderState");
Customer customer = (Customer) call.getArgs()[0];
Order order = orderState.getOrder(customer);
if (order != null) {
returnValue = order;
} else {
returnValue = call.proceed();
returnValue = orderState.setOrder(customer, (Order) returnValue);
}
return returnValue;
}
Aggregations