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.
Public Properties ​
Property | Description |
---|---|
allOrderStatuses | craft\commerce\models\OrderStatus[], array – all Order Statuses |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
defaultOrderStatus | craft\commerce\models\OrderStatus, null – default order status from the DB |
defaultOrderStatusId | null, integer – default order status ID from the DB |
orderCountByStatus | array |
allOrderStatuses
​
- Type
- craft\commerce\models\OrderStatus[], array
- Default value
null
all Order Statuses
defaultOrderStatus
​
- Type
- craft\commerce\models\OrderStatus, null
- Default value
null
default order status from the DB
defaultOrderStatusId
​
default order status ID from the DB
orderCountByStatus
​
- Type
- array
- Default value
null
Public Methods ​
Method | Description |
---|---|
__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 a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be 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 it's 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 control-panel-configured default order status. |
getDefaultOrderStatusId() | Get default order status ID from the DB |
getOrderCountByStatus() | |
getOrderStatusByHandle() | Get order status by its handle. |
getOrderStatusById() | Get an order status by ID |
getOrderStatusByUid() | Get an order status by ID |
handleChangedOrderStatus() | Handle order status change. |
handleDeletedOrderStatus() | Handle order status being deleted |
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 for this component. |
init() | Initializes the object. |
off() | Detaches an existing event handler from this component. |
on() | 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() | Triggers an event. |
deleteOrderStatusById()
​
Delete an order status by it's id.
Arguments ​
$id
$storeId
Throws ​
getAllOrderStatuses()
​
- Since
- 2.2
Returns all Order Statuses
Arguments ​
Returns ​
\Illuminate\Support\Collection<\craft\commerce\models\OrderStatus>
Throws ​
getDefaultOrderStatus()
​
Get default order status from the DB
Arguments ​
$storeId
getDefaultOrderStatusForOrder()
​
Get the default order status for a particular order. Defaults to the control-panel-configured default order status.
Arguments ​
$order
getDefaultOrderStatusId()
​
Get default order status ID from the DB
Arguments ​
$storeId
getOrderCountByStatus()
​
- Since
- 3.0.11
Arguments ​
$storeId
getOrderStatusByHandle()
​
Get order status by its handle.
Arguments ​
$handle
$storeId
getOrderStatusById()
​
Get an order status by ID
Arguments ​
$id
$storeId
getOrderStatusByUid()
​
Get an order status by ID
Arguments ​
$uid
$storeId
handleChangedOrderStatus()
​
Handle order status change.
Arguments ​
$event
Returns ​
void
Throws ​
- Throwable
if reasons
handleDeletedOrderStatus()
​
Handle order status being deleted
Arguments ​
$event
Returns ​
void
Throws ​
- Throwable
if reasons
pruneDeletedEmail()
​
Prune a deleted email from order statuses.
Arguments ​
$event
reorderOrderStatuses()
​
Reorders the order statuses.
Arguments ​
$ids
Throws ​
- yii\base\Exception
- yii\base\ErrorException
- yii\base\NotSupportedException
- yii\web\ServerErrorHttpException
saveOrderStatus()
​
Save the order status.
Arguments ​
$orderStatus
$emailIds
$runValidation
(boolean) – Should we validate this order status before saving.$force
Throws ​
statusChangeHandler()
​
Handler for order status change event
Arguments ​
$order
(craft\commerce\elements\Order)$orderHistory
(craft\commerce\models\OrderHistory)
Throws ​
Constants ​
Constant | Description |
---|---|
CONFIG_STATUSES_KEY |
Events ​
EVENT_DEFAULT_ORDER_STATUS ​
The event that is triggered when a default order status is being fetched.
Set the event object’s orderStatus
property to override the default status set in the control panel.
use craft\commerce\events\DefaultOrderStatusEvent;
use craft\commerce\services\OrderStatuses;
use craft\commerce\models\OrderStatus;
use craft\commerce\elements\Order;
use yii\base\Event;
Event::on(
OrderStatuses::class,
OrderStatuses::EVENT_DEFAULT_ORDER_STATUS,
function(DefaultOrderStatusEvent $event) {
// @var OrderStatus $status
$status = $event->orderStatus;
// @var Order $order
$order = $event->order;
// Choose a more appropriate order status than the control panel default
// ...
}
);
EVENT_ORDER_STATUS_CHANGE_EMAILS ​
The email event that is triggered when an order status is changed.
Plugins can get notified when an order status is changed
use craft\commerce\events\OrderStatusEmailsEvent;
use craft\commerce\services\OrderStatuses;
use craft\commerce\models\OrderHistory;
use craft\commerce\elements\Order;
use yii\base\Event;
Event::on(
OrderStatuses::class,
OrderStatuses::EVENT_ORDER_STATUS_CHANGE_EMAILS,
function(OrderStatusEmailsEvent $event) {
// @var OrderHistory $orderHistory
$orderHistory = $event->orderHistory;
// @var Order $order
$order = $event->order;
// Let the delivery department know the order’s ready to be delivered
// ...
}
);