OrderStatuses

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

Order status service.

View source

Public Properties

$allOrderStatuses

Signature

public craft\commerce\models\OrderStatus[] getAllOrderStatuses ( )

$defaultOrderStatus

Signature

public craft\commerce\models\OrderStatus, null getDefaultOrderStatus ( )

$defaultOrderStatusId

Type
integer, null
Access
Read-only

View source

Signature

public integer, null getDefaultOrderStatusId ( )

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.
deleteOrderStatusById()Delete an order status by ID
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.
getAllOrderStatuses()Returns all Order Statuses
getBehavior()Returns the named behavior object.
getBehaviors()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
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.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
reorderOrderStatuses()Reorders the order statuses.
saveOrderStatus()Save the order status.
statusChangeHandler()Handler for order status change event
trigger()Triggers an event.

deleteOrderStatusById()

Delete an order status by ID

View source

Arguments

  • $id

Returns

boolean

Throws

Signature

public boolean deleteOrderStatusById ( $id )

getAllOrderStatuses()

Returns all Order Statuses

View source

Returns

craft\commerce\models\OrderStatus[]

Signature

public craft\commerce\models\OrderStatus[] getAllOrderStatuses ( )

getDefaultOrderStatus()

Get default order status from the DB

View source

Returns

craft\commerce\models\OrderStatus, null

Signature

public craft\commerce\models\OrderStatus, null getDefaultOrderStatus ( )

getDefaultOrderStatusForOrder()

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

View source

Arguments

Returns

craft\commerce\models\OrderStatus, null

Signature

public craft\commerce\models\OrderStatus, null getDefaultOrderStatusForOrder ( craft\commerce\elements\Order $order )

getDefaultOrderStatusId()

Get default order status ID from the DB

View source

Returns

integer, null

Signature

public integer, null getDefaultOrderStatusId ( )

getOrderStatusByHandle()

Get order status by its handle.

View source

Arguments

Returns

craft\commerce\models\OrderStatus, null

Signature

public craft\commerce\models\OrderStatus, null getOrderStatusByHandle ( $handle )

getOrderStatusById()

Get an order status by ID

View source

Arguments

Returns

craft\commerce\models\OrderStatus, null

Signature

public craft\commerce\models\OrderStatus, null getOrderStatusById ( $id )

reorderOrderStatuses()

Reorders the order statuses.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean reorderOrderStatuses ( array $ids )

saveOrderStatus()

Save the order status.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveOrderStatus ( craft\commerce\models\OrderStatus $model, array $emailIds, \craft\commerce\services\bool $runValidation = true )

statusChangeHandler()

Handler for order status change event

View source

Arguments

Signature

public void statusChangeHandler ( $order, $orderHistory )

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
});