Customers
- Type
- Class
- Namespace
- craft\commerce\services
- Inherits
- craft\commerce\services\Customers » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 2.0
Customer service.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
allCustomers | array (opens new window), craft\commerce\models\Customer[] |
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
customer | craft\commerce\models\Customer |
customerId | integer (opens new window) – id of current customer record |
customersQuery | craft\db\Query (opens new window) |
savedCustomer | craft\commerce\models\Customer |
userGroupIdsForUser | array (opens new window) |
# allCustomers
- Type
- array (opens new window), craft\commerce\models\Customer[]
- Default value
null
View source (opens new window)
# customer
- Type
- craft\commerce\models\Customer
- Default value
null
View source (opens new window)
# customerId
- Type
- integer (opens new window)
- Default value
null
id of current customer record
View source (opens new window)
# customersQuery
- Type
- craft\db\Query (opens new window)
- Default value
null
- Access
- Read-only
- Since
- 3.1
View source (opens new window)
# savedCustomer
- Type
- craft\commerce\models\Customer
- Default value
null
View source (opens new window)
# userGroupIdsForUser
- Type
- array (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
addEditUserCustomerInfoTab() | |
addEditUserCustomerInfoTabContent() | Add customer info to the Edit User page in the CP |
afterSaveUserHandler() | |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
consolidateGuestOrdersByEmail() | Consolidate all guest orders for this email address to use one customer record. |
consolidateOrdersToUser() | Assigns guest orders to a user. |
deleteCustomer() | Delete a customer. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
eagerLoadCustomerForOrders() | |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
forgetCustomer() | Forgets a Customer by deleting the customer from session and request. |
getAddressIds() | Get all address IDs for a customer by its ID. |
getAllCustomers() | Get all customers. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | Returns all behaviors attached to this component. |
getCustomer() | Get the current customer by the current customer in session, or creates one if none exists. |
getCustomerById() | Get a customer by its ID. |
getCustomerByUserId() | Get a customer by user ID. Returns null, if it doesn't exist. |
getCustomerId() | Id of current customer record. Guaranteed not null |
getCustomersQuery() | Retrieve customer query with the option to specify a search term |
getUserGroupIdsForUser() | Returns the user groups of the user param but defaults to the current user |
hasEventHandlers() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined for this component. |
init() (opens new window) | Initializes the object. |
loginHandler() | When a user logs in, consolidate all his/her orders. |
logoutHandler() | Handle the user logout. |
off() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | Attaches an event handler to an event. |
orderCompleteHandler() | Sets the last used addresses on the customer on order completion. |
purgeOrphanedCustomers() | Deletes any customer record not related to a user or a cart. |
saveAddress() | Associates an address with the saved customer, and saves the address. |
saveCustomer() | Save a customer by its model. |
saveUserHandler() | Handle a saved user. |
trigger() (opens new window) | Triggers an event. |
# addEditUserCustomerInfoTab()
- Since
- 2.2
View source (opens new window)
Arguments
$context
(array (opens new window))
# addEditUserCustomerInfoTabContent()
- Since
- 2.2
Add customer info to the Edit User page in the CP
View source (opens new window)
Arguments
$context
(array (opens new window))
Returns
Throws
\Twig\Error\LoaderError
\Twig\Error\RuntimeError
\Twig\Error\SyntaxError
- yii\base\InvalidConfigException (opens new window)
# afterSaveUserHandler()
View source (opens new window)
Arguments
Throws
# consolidateGuestOrdersByEmail()
- Since
- 3.1.4
Consolidate all guest orders for this email address to use one customer record.
View source (opens new window)
Arguments
$email
(string (opens new window))$order
(craft\commerce\elements\Order, null (opens new window))
Throws
# consolidateOrdersToUser()
Assigns guest orders to a user.
View source (opens new window)
Arguments
$user
(craft\elements\User (opens new window))$orders
Returns
# deleteCustomer()
Delete a customer.
View source (opens new window)
Arguments
$customer
(craft\commerce\models\Customer)
Returns
mixed
# eagerLoadCustomerForOrders()
- Since
- 3.2.0
View source (opens new window)
Arguments
$orders
(array (opens new window), craft\commerce\elements\Order[])
Returns
craft\commerce\elements\Order[]
# forgetCustomer()
Forgets a Customer by deleting the customer from session and request.
View source (opens new window)
# getAddressIds()
Get all address IDs for a customer by its ID.
View source (opens new window)
Arguments
$customerId
Returns
# getAllCustomers()
Get all customers.
View source (opens new window)
Returns
craft\commerce\models\Customer[]
# getCustomer()
Get the current customer by the current customer in session, or creates one if none exists.
View source (opens new window)
Returns
craft\commerce\models\Customer
# getCustomerById()
Get a customer by its ID.
View source (opens new window)
Arguments
Returns
craft\commerce\models\Customer, null (opens new window)
# getCustomerByUserId()
Get a customer by user ID. Returns null, if it doesn't exist.
View source (opens new window)
Arguments
$id
Returns
craft\commerce\models\Customer, null (opens new window)
# getCustomerId()
DEPRECATED
Deprecated in 3.1.11. Use Customers::getCustomer()->id
instead.
Id of current customer record. Guaranteed not null
View source (opens new window)
Returns
Throws
# getCustomersQuery()
- Since
- 3.1
Retrieve customer query with the option to specify a search term
View source (opens new window)
Arguments
$search
(string (opens new window), null (opens new window))
Returns
craft\db\Query (opens new window)
# getUserGroupIdsForUser()
Returns the user groups of the user param but defaults to the current user
View source (opens new window)
Arguments
Returns
# loginHandler()
When a user logs in, consolidate all his/her orders.
View source (opens new window)
Arguments
$event
(yii\web\UserEvent (opens new window))
# logoutHandler()
Handle the user logout.
View source (opens new window)
Arguments
$event
(yii\web\UserEvent (opens new window))
# orderCompleteHandler()
Sets the last used addresses on the customer on order completion.
Consolidates any other orders using the same email address.
Duplicates the address records used for the order so they are independent to the customers address book.
View source (opens new window)
Arguments
$order
(craft\commerce\elements\Order)
Throws
# purgeOrphanedCustomers()
- Since
- 2.2
Deletes any customer record not related to a user or a cart.
View source (opens new window)
# saveAddress()
Associates an address with the saved customer, and saves the address.
View source (opens new window)
Arguments
$address
(craft\commerce\models\Address)$customer
(craft\commerce\models\Customer, null (opens new window)) – Defaults to the current customer in session if none is passing in.$runValidation
(boolean (opens new window)) – Should we validate this address before saving.
Returns
Throws
# saveCustomer()
Save a customer by its model.
View source (opens new window)
Arguments
$customer
(craft\commerce\models\Customer)$runValidation
(boolean (opens new window)) – Should we validate this customer before saving.
Returns
Throws
# saveUserHandler()
DEPRECATED
Deprecated in 3.1.11. Use afterSaveUserHandler() instead.
Handle a saved user.
View source (opens new window)
Arguments
$event
(yii\base\Event (opens new window))
Throws
# Constants
Constant | Description |
---|---|
SESSION_CUSTOMER |
# Events
# EVENT_AFTER_SAVE_CUSTOMER
The event that is triggered after customer details is saved.
# EVENT_AFTER_SAVE_CUSTOMER_ADDRESS
The event that is triggered after customer address is successfully saved.
# EVENT_BEFORE_SAVE_CUSTOMER
The event that is triggered before customer details is saved.
# EVENT_BEFORE_SAVE_CUSTOMER_ADDRESS
The event that is triggered before customer address is saved.
← Currencies Discounts →