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

Signature

public craft\commerce\models\Customer[] getAllCustomers ( )

$customer

Signature

public craft\commerce\models\Customer getCustomer ( )

$customerId

Type
integer
Access
Read-only

View source

Signature

public integer getCustomerId ( )

$userGroupIdsForUser

Type
array
Access
Read-only

View source

Signature

public array getUserGroupIdsForUser ( craft\elements\User $user = null )

Public Methods

MethodDescription
__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 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.
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.
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
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.
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.
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.

consolidateOrdersToUser()

Assigns guest orders to a user.

View source

Arguments

Returns

boolean

Signature

public boolean consolidateOrdersToUser ( craft\elements\User $user, array $orders = null )

deleteCustomer()

Delete a customer.

View source

Arguments

Returns

mixed

Signature

public mixed deleteCustomer ( $customer )

forgetCustomer()

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

View source

Signature

public void forgetCustomer ( )

getAddressIds()

Get all address IDs for a customer by its ID.

View source

Arguments

  • $customerId

Returns

array

Signature

public array getAddressIds ( $customerId )

getAllCustomers()

Signature

public craft\commerce\models\Customer[] getAllCustomers ( )

getCustomer()

Get the current customer.

View source

Returns

craft\commerce\models\Customer

Signature

public craft\commerce\models\Customer getCustomer ( )

getCustomerById()

Get a customer by its ID.

View source

Arguments

Returns

craft\commerce\models\Customer, null

Signature

public craft\commerce\models\Customer, null getCustomerById ( \craft\commerce\services\int $id )

getCustomerByUserId()

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

View source

Arguments

  • $id

Returns

craft\commerce\models\Customer, null

Signature

public craft\commerce\models\Customer, null getCustomerByUserId ( $id )

getCustomerId()

Id of current customer record. Guaranteed not null

View source

Returns

integer

Throws

Signature

public integer getCustomerId ( )

getUserGroupIdsForUser()

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

View source

Arguments

Returns

array

Signature

public array getUserGroupIdsForUser ( craft\elements\User $user = null )

loginHandler()

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

View source

Arguments

Signature

public void loginHandler ( yii\web\UserEvent $event )

logoutHandler()

Handle the user logout.

View source

Arguments

Throws

Signature

public void logoutHandler ( yii\web\UserEvent $event )

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

Signature

public void orderCompleteHandler ( $order )

saveAddress()

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

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveAddress ( craft\commerce\models\Address $address, craft\commerce\models\Customer $customer = null, \craft\commerce\services\bool $runValidation = true )

saveCustomer()

Save a customer by its model.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveCustomer ( craft\commerce\models\Customer $customer, \craft\commerce\services\bool $runValidation = true )

saveUserHandler()

Handle a saved user.

View source

Arguments

Throws

Signature

public void saveUserHandler ( yii\base\Event $event )

Constants

ConstantDescription
SESSION_CUSTOMER