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

# 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

# addEditUserCustomerInfoTabContent()

Since
2.2

Add customer info to the Edit User page in the CP

View source (opens new window)

Arguments

Returns

string (opens new window)

Throws

# 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

Throws

# consolidateOrdersToUser()

Assigns guest orders to a user.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# deleteCustomer()

Delete a customer.

View source (opens new window)

Arguments

Returns

mixed

# eagerLoadCustomerForOrders()

Since
3.2.0

View source (opens new window)

Arguments

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

array (opens new window)

# 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

integer (opens new window)

Throws

# getCustomersQuery()

Since
3.1

Retrieve customer query with the option to specify a search term

View source (opens new window)

Arguments

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

array (opens new window)

# loginHandler()

When a user logs in, consolidate all his/her orders.

View source (opens new window)

Arguments

# logoutHandler()

Handle the user logout.

View source (opens new window)

Arguments

# 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

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

Returns

boolean (opens new window)

Throws

# saveCustomer()

Save a customer by its model.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Throws

# saveUserHandler()

DEPRECATED

Deprecated in 3.1.11. Use afterSaveUserHandler() instead.

Handle a saved user.

View source (opens new window)

Arguments

Throws

# Constants

Constant Description
SESSION_CUSTOMER

# Events

# EVENT_AFTER_SAVE_CUSTOMER

Type
craft\commerce\events\CustomerEvent

The event that is triggered after customer details is saved.

# EVENT_AFTER_SAVE_CUSTOMER_ADDRESS

Type
craft\commerce\events\CustomerAddressEvent

The event that is triggered after customer address is successfully saved.

# EVENT_BEFORE_SAVE_CUSTOMER

Type
craft\commerce\events\CustomerEvent

The event that is triggered before customer details is saved.

# EVENT_BEFORE_SAVE_CUSTOMER_ADDRESS

Type
craft\commerce\events\CustomerAddressEvent

The event that is triggered before customer address is saved.