@Override
public void onApplicationEvent(final CustomerPersistedEvent event) {
Customer dbCustomer = event.getCustomer();
//if there is an active request, remove the session-based customer if it exists and update CustomerState
WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
if (request != null) {
String customerAttribute = CustomerStateRequestProcessor.getAnonymousCustomerSessionAttributeName();
String customerIdAttribute = CustomerStateRequestProcessor.getAnonymousCustomerIdSessionAttributeName();
if (BLCRequestUtils.isOKtoUseSession(request)) {
Customer sessionCustomer = (Customer) request.getAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
//invalidate the session-based customer if it's there and the ID is the same as the Customer that has been
//persisted
if (sessionCustomer != null && sessionCustomer.getId().equals(dbCustomer.getId())) {
request.removeAttribute(customerAttribute, WebRequest.SCOPE_GLOBAL_SESSION);
request.setAttribute(customerIdAttribute, dbCustomer.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
}
}
//Update CustomerState if the persisted Customer ID is the same
if (CustomerState.getCustomer() != null && CustomerState.getCustomer().getId().equals(dbCustomer.getId())) {