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 | 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) |
userGroupIdsForUser | array (opens new window) |
# allCustomers
- Type
- craft\commerce\models\Customer[]
- Access
- Read-only
View source (opens new window)
# customer
- Type
- craft\commerce\models\Customer
- Access
- Read-only
View source (opens new window)
# customerId
- Type
- integer (opens new window)
- Access
- Read-only
View source (opens new window)
# userGroupIdsForUser
- Type
- array (opens new window)
- 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 an object property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets value of an object property. |
__unset() (opens new window) | Sets an object property to null. |
_createUserFromOrder() | |
addEditUserCustomerInfoTab() | |
addEditUserCustomerInfoTabContent() | Add customer info to the Edit User page in the CP |
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. |
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. |
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. |
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 |
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. |
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. |
# _createUserFromOrder()
View source (opens new window)
Arguments
$order
(craft\commerce\elements\Order)
Returns
void
Throws
- yii\base\Exception (opens new window)
- Throwable (opens new window)
- craft\errors\ElementNotFoundException (opens new window)
# 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)
# 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
# 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.
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()
Id of current customer record. Guaranteed not null
View source (opens new window)
Returns
Throws
# 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.
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)
# 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()
Handle a saved user.
View source (opens new window)
Arguments
$event
(yii\base\Event (opens new window))
Throws
# Constants
Constant | Description |
---|---|
SESSION_CUSTOMER |
← Currencies Discounts →