Skip to content

CustomerBehavior ​

Type
Class
Namespace
craft\commerce\behaviors
Inherits
craft\commerce\behaviors\CustomerBehavior » yii\base\Behavior » yii\base\BaseObject
Implements
yii\base\Configurable
Since
4.0

Customer behavior.

View source

Public Properties ​

PropertyDescription
activeCartsarray
addressescraft\elements\Address
inactiveCartsarray
orderscraft\commerce\elements\Order[]
ownercraft\elements\User
primaryBillingAddressnull, craft\elements\Address
primaryBillingAddressIdnull, integer
primaryPaymentSourcenull, craft\commerce\models\PaymentSource
primaryPaymentSourceIdnull, integer
primaryShippingAddressnull, craft\elements\Address
primaryShippingAddressIdnull, integer
subscriptionscraft\commerce\elements\Subscription[]

activeCarts ​

Type
array
Default value
null

View source

addresses ​

Type
craft\elements\Address
Default value
null

View source

inactiveCarts ​

Type
array
Default value
null

View source

orders ​

Type
craft\commerce\elements\Order[]
Default value
null

View source

owner ​

Type
craft\elements\User
Default value
null

View source

primaryBillingAddress ​

Type
null, craft\elements\Address
Default value
null

View source

primaryBillingAddressId ​

Type
null, integer
Default value
null

View source

primaryPaymentSource ​

Type
null, craft\commerce\models\PaymentSource
Default value
null

View source

primaryPaymentSourceId ​

Type
null, integer
Default value
null

View source

primaryShippingAddress ​

Type
null, craft\elements\Address
Default value
null

View source

primaryShippingAddressId ​

Type
null, integer
Default value
null

View source

subscriptions ​

Type
craft\commerce\elements\Subscription[]
Default value
null

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
afterSaveUserHandler()
attach()Attaches the behavior object to the component.
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.
defineFields()
defineRules()
detach()Detaches the behavior object from the component.
events()Declares event handlers for the owner's events.
getActiveCarts()
getInactiveCarts()
getOrders()Returns the completed order elements associated with this user.
getPrimaryBillingAddress()
getPrimaryBillingAddressId()
getPrimaryPaymentSource()
getPrimaryPaymentSourceId()
getPrimaryShippingAddress()
getPrimaryShippingAddressId()
getSubscriptions()Returns the subscription elements associated with this customer.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
setPrimaryBillingAddressId()
setPrimaryPaymentSourceId()
setPrimaryShippingAddressId()

afterSaveUserHandler() ​

View source

Arguments ​

Returns ​

void

Throws ​

attach() ​

Attaches the behavior object to the component.

The default implementation will set the owner property and attach event handlers as declared in events(). Make sure you call the parent implementation if you override this method.

View source

Arguments ​

  • $owner (yii\base\Component) – The component that this behavior is to be attached to.

defineFields() ​

Since
5.0.10

View source

Arguments ​

Returns ​

void

defineRules() ​

View source

Arguments ​

Throws ​

events() ​

Declares event handlers for the owner's events.

Child classes may override this method to declare what PHP callbacks should be attached to the events of the owner component.

The callbacks will be attached to the owner's events when the behavior is attached to the owner; and they will be detached from the events when the behavior is detached from the component.

The callbacks can be any of the following:

  • method in this behavior: 'handleClick', equivalent to [$this, 'handleClick']
  • object method: [$object, 'handleClick']
  • static method: ['Page', 'handleClick']
  • anonymous function: function ($event) { ... }

The following is an example:

php
[
    Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate',
    Model::EVENT_AFTER_VALIDATE => 'myAfterValidate',
]

View source

Returns ​

array – Events (array keys) and the corresponding event handler methods (array values).

getActiveCarts() ​

View source

Returns ​

array

Throws ​

getInactiveCarts() ​

View source

Returns ​

array

Throws ​

getOrders() ​

Returns the completed order elements associated with this user.

Orders are returned with the most recent first.

View source

Returns ​

craft\commerce\elements\Order[]

getPrimaryBillingAddress() ​

View source

Returns ​

craft\elements\Address, null

getPrimaryBillingAddressId() ​

View source

Returns ​

integer, null

getPrimaryPaymentSource() ​

Since
4.2

View source

Returns ​

craft\commerce\models\PaymentSource, null

Throws ​

getPrimaryPaymentSourceId() ​

Since
4.2

View source

Returns ​

integer, null

Throws ​

getPrimaryShippingAddress() ​

View source

Returns ​

craft\elements\Address, null

getPrimaryShippingAddressId() ​

View source

Returns ​

integer, null

getSubscriptions() ​

Returns the subscription elements associated with this customer.

View source

Returns ​

craft\commerce\elements\Subscription[]

setPrimaryBillingAddressId() ​

View source

Arguments ​

setPrimaryPaymentSourceId() ​

Since
4.2

View source

Arguments ​

Returns ​

void

setPrimaryShippingAddressId() ​

View source

Arguments ​