OrderStatuses

Type
Class
Namespace
craft\commerce\services
Inherits
craft\commerce\services\OrderStatuses » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
2.0

Order status service.

View source (opens new window)

# Public Properties

# allOrderStatuses

Type
craft\commerce\models\OrderStatus[]
Access
Read-only
Since
2.2

View source (opens new window)

# defaultOrderStatus

Type
craft\commerce\models\OrderStatus, null (opens new window)
Access
Read-only

View source (opens new window)

# defaultOrderStatusId

Type
integer (opens new window), null (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.
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.
deleteOrderStatusById() Delete an order status by it's id.
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.
getAllOrderStatuses() Returns all Order Statuses
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getDefaultOrderStatus() Get default order status from the DB
getDefaultOrderStatusForOrder() Get the default order status for a particular order. Defaults to the CP configured default order status.
getDefaultOrderStatusId() Get default order status ID from the DB
getOrderStatusByHandle() Get order status by its handle.
getOrderStatusById() Get an order status by ID
handleChangedOrderStatus() Handle order status change.
handleDeletedOrderStatus() Handle order status being deleted
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.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
pruneDeletedEmail() Prune a deleted email from order statuses.
reorderOrderStatuses() Reorders the order statuses.
saveOrderStatus() Save the order status.
statusChangeHandler() Handler for order status change event
trigger() (opens new window) Triggers an event.

# deleteOrderStatusById()

Delete an order status by it's id.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Throws

# getAllOrderStatuses()

Since
2.2

Returns all Order Statuses

View source (opens new window)

Arguments

Returns

craft\commerce\models\OrderStatus[]

# getDefaultOrderStatus()

Get default order status from the DB

View source (opens new window)

Returns

craft\commerce\models\OrderStatus, null (opens new window)

# getDefaultOrderStatusForOrder()

Get the default order status for a particular order. Defaults to the CP configured default order status.

View source (opens new window)

Arguments

Returns

craft\commerce\models\OrderStatus, null (opens new window)

# getDefaultOrderStatusId()

Get default order status ID from the DB

View source (opens new window)

Returns

integer (opens new window), null (opens new window)

# getOrderStatusByHandle()

Get order status by its handle.

View source (opens new window)

Arguments

Returns

craft\commerce\models\OrderStatus, null (opens new window)

# getOrderStatusById()

Get an order status by ID

View source (opens new window)

Arguments

Returns

craft\commerce\models\OrderStatus, null (opens new window)

# handleChangedOrderStatus()

Handle order status change.

View source (opens new window)

Arguments

Returns

void

Throws

# handleDeletedOrderStatus()

Handle order status being deleted

View source (opens new window)

Arguments

Returns

void

Throws

# pruneDeletedEmail()

Prune a deleted email from order statuses.

View source (opens new window)

Arguments

# reorderOrderStatuses()

Reorders the order statuses.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Throws

# saveOrderStatus()

Save the order status.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Throws

# statusChangeHandler()

Handler for order status change event

View source (opens new window)

Arguments

# Constants

Constant Description
CONFIG_STATUSES_KEY

# Events

# EVENT_DEFAULT_ORDER_STATUS

Type
craft\commerce\events\DefaultOrderStatusEvent

The event that is triggered when getting a default status for an order. You may set craft\commerce\events\DefaultOrderStatusEvent::$orderStatus to a desired OrderStatus to override the default status set in CP

Plugins can get notified when a default order status is being fetched

use craft\commerce\events\DefaultOrderStatusEvent;
use craft\commerce\services\OrderStatuses;
use yii\base\Event;

Event::on(OrderStatuses::class, OrderStatuses::EVENT_DEFAULT_ORDER_STATUS, function(DefaultOrderStatusEvent $e) {
    // Do something - perhaps figure out a better default order statues than the one set in CP
});