Customers

Type
Class
Namespace
craft\commerce\services
Inherits
craft\commerce\services\Customers » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
2.0

Customer service.

View source

# Public Properties

# allCustomers

Type
craft\commerce\models\Customer[]
Access
Read-only

View source

# customer

Type
craft\commerce\models\Customer
Access
Read-only

View source

# customerId

Type
integer
Access
Read-only

View source

# customersQuery

Type
craft\db\Query
Access
Read-only
Since
3.1

View source

# userGroupIdsForUser

Type
array
Access
Read-only

View source

# Public Methods

Method Description
__call() Calls the named method which is not a class method.
__clone() This method is called after the object is created by cloning an existing one.
__construct() Constructor.
__get() Returns the value of a component property.
__isset() Checks if a property is set, i.e. defined and not null.
__set() Sets the value of a component property.
__unset() Sets a component property to be null.
_createUserFromOrder()
addEditUserCustomerInfoTab()
addEditUserCustomerInfoTabContent() Add customer info to the Edit User page in the CP
afterSaveUserHandler()
attachBehavior() Attaches a behavior to this component.
attachBehaviors() Attaches a list of behaviors to the component.
behaviors() Returns a list of behaviors that this component should behave as.
canGetProperty() Returns a value indicating whether a property can be read.
canSetProperty() Returns a value indicating whether a property can be set.
className() 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() Detaches a behavior from the component.
detachBehaviors() Detaches all behaviors from the component.
ensureBehaviors() Makes sure that the behaviors declared in behaviors() 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() Returns the named behavior object.
getBehaviors() Returns all behaviors attached to this component.
getCustomer() Get the current customer.
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() Returns a value indicating whether there is any handler attached to the named event.
hasMethod() Returns a value indicating whether a method is defined.
hasProperty() Returns a value indicating whether a property is defined for this component.
init() Initializes the object.
loginHandler() When a user logs in, consolidate all his/her orders.
logoutHandler() Handle the user logout.
off() Detaches an existing event handler from this component.
on() 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() Triggers an event.

# _createUserFromOrder()

View source

Arguments

Returns

void

Throws

# addEditUserCustomerInfoTab()

Since
2.2

View source

Arguments

# addEditUserCustomerInfoTabContent()

Since
2.2

Add customer info to the Edit User page in the CP

View source

Arguments

Returns

string

Throws

# afterSaveUserHandler()

View source

Arguments

Throws

# consolidateGuestOrdersByEmail()

Since
3.1.4

Consolidate all guest orders for this email address to use one customer record.

View source

Arguments

Throws

# consolidateOrdersToUser()

Assigns guest orders to a user.

View source

Arguments

Returns

boolean

# deleteCustomer()

Delete a customer.

View source

Arguments

Returns

mixed

# forgetCustomer()

Forgets a Customer by deleting the customer from session and request.

View source

# getAddressIds()

Get all address IDs for a customer by its ID.

View source

Arguments

  • $customerId

Returns

array

# getAllCustomers()

Get all customers.

View source

Returns

craft\commerce\models\Customer[]

# getCustomer()

Get the current customer.

View source

Returns

craft\commerce\models\Customer

# getCustomerById()

Get a customer by its ID.

View source

Arguments

Returns

craft\commerce\models\Customer, null

# getCustomerByUserId()

Get a customer by user ID. Returns null, if it doesn't exist.

View source

Arguments

  • $id

Returns

craft\commerce\models\Customer, null

# getCustomerId()

DEPRECATED

Deprecated since version 3.x:

Id of current customer record. Guaranteed not null

View source

Returns

integer

Throws

# getCustomersQuery()

Since
3.1

Retrieve customer query with the option to specify a search term

View source

Arguments

Returns

craft\db\Query

# getUserGroupIdsForUser()

Returns the user groups of the user param but defaults to the current user

View source

Arguments

Returns

array

# loginHandler()

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

View source

Arguments

# logoutHandler()

Handle the user logout.

View source

Arguments

# orderCompleteHandler()

Sets the last used addresses on the customer on order completion.

Duplicates the address records used for the order so they are independent to the customers address book.

View source

Arguments

# purgeOrphanedCustomers()

Since
2.2

Deletes any customer record not related to a user or a cart.

View source

# saveAddress()

Associates an address with the saved customer, and saves the address.

View source

Arguments

Returns

boolean

Throws

# saveCustomer()

Save a customer by its model.

View source

Arguments

Returns

boolean

Throws

# saveUserHandler()

DEPRECATED

Deprecated since version 3.x:

Handle a saved user.

View source

Arguments

Throws

# Constants

Constant Description
SESSION_CUSTOMER