Class CustomerStateRefresher
java.lang.Object
org.broadleafcommerce.profile.web.core.CustomerStateRefresher
- All Implemented Interfaces:
EventListener,org.springframework.context.ApplicationListener<org.broadleafcommerce.profile.core.domain.CustomerPersistedEvent>
@Component("blCustomerStateRefresher")
public class CustomerStateRefresher
extends Object
implements org.springframework.context.ApplicationListener<org.broadleafcommerce.profile.core.domain.CustomerPersistedEvent>
ApplicationListener responsible for updating CustomerState as well as invalidating the session-based
customer, if one existed previously. For instance, when originally browsing the catalog a Customer is created but only
stored in session and retrieved from session on subsequent requests. However, once the Customer has been persisted
(like when they add something to the cart) then this component is responsible for updating CustomerState as well
as invalidating the session-based customer.- Author:
- Phillip Verheyden (phillipuniverse)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonApplicationEvent(org.broadleafcommerce.profile.core.domain.CustomerPersistedEvent event) Removes the completeCustomerstored in session and adds a new session variable for just the customer ID.protected voidresetTransientFields(org.broadleafcommerce.profile.core.domain.Customer preMergedCustomer, org.broadleafcommerce.profile.core.domain.Customer postMergedCustomer) After a JPA merge occurs, there is a new object created representing the merged changes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Constructor Details
-
CustomerStateRefresher
public CustomerStateRefresher()
-
-
Method Details
-
onApplicationEvent
public void onApplicationEvent(org.broadleafcommerce.profile.core.domain.CustomerPersistedEvent event) Removes the completeCustomerstored in session and adds a new session variable for just the customer ID. This should occur once the session-basedCustomer(all anonymous Customers start out this way) has been persisted.Also updates
CustomerStatewith the persistedCustomerso that it will always represent the most up-to-date version that is in the database- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.broadleafcommerce.profile.core.domain.CustomerPersistedEvent>- Parameters:
event-
-
resetTransientFields
protected void resetTransientFields(org.broadleafcommerce.profile.core.domain.Customer preMergedCustomer, org.broadleafcommerce.profile.core.domain.Customer postMergedCustomer) After a JPA merge occurs, there is a new object created representing the merged changes. The new object does not reflect the state of transient fields that may have been set on the object that was merged.This method, by default, resets the state of transient properties. and allows the user to override this method to set additional (or different) transient values.
- Parameters:
preMergedCustomer-postMergedCustomer-
-