Customer & ShopUser
For handling customers of your system Sylius is using a combination of two entities - Customer and ShopUser. The difference between these two entities is simple: the Customer is a guest in your shop and the ShopUser is a user registered in the system - they have an account.
Customer
The Customer entity was created to collect data about non-registered guests of the system - ones that has been buying without having an account or that have somehow provided us with their e-mail.
How to create a Customer programmatically?
As usual, use a factory. The only required field for the Customer entity is email
, provide it before adding it to the repository.
The Customer entity can of course hold other information besides an email, it can be for instance firstName
, lastName
or birthday
.
The relation between the Customer and the ShopUser is bidirectional. Both entities hold a reference to each other.
ShopUser
ShopUser entity is designed for customers that have registered in the system - they have an account with both e-mail and password. They can visit and modify their account.
While creating a new account the existence of the provided email in the system is checked - if the email was present - it will already have a Customer therefore the existing one will be assigned to the newly created ShopUser, if not, a new Customer will be created together with the ShopUser.
Please note that if a newly created ShopUser has been assigned to an existing Customer, they will have access to previously placed orders as a guest.
How to create a ShopUser programmatically?
Assuming that you have a Customer (either retrieved from the repository or a newly created one) - use a factory to create a new ShopUser, and assign the existing Customer and a password via the setPlainPassword()
method.
Changing the ShopUser password
The already set password of a ShopUser can be easily changed via the setPlainPassword()
method.
Customer related events
Event id | Description |
---|---|
| dispatched when a new Customer is registered |
| dispatched when a Customer is updated |
| dispatched when an OAuthUser is created |
| dispatched when an OAuthUser is updated |
| dispatched when a User is created |
| dispatched when a User is updated |
| dispatched before a User is deleted |
| dispatched when a verification token is requested |
| dispatched when a reset password token is requested |
| dispatched before user password is changed |
| dispatched before user password is reset |
| dispatched when an implicit login is done |
| dispatched when an interactive login is done |
Last updated