Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
128 lines (108 sloc) 2.38 KB
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\commerce\models;
use craft\commerce\base\Model;
use craft\commerce\Plugin;
use craft\commerce\records\OrderStatus as OrderStatusRecord;
use craft\helpers\UrlHelper;
use craft\validators\UniqueValidator;
/**
* Order status model.
*
* @property string $cpEditUrl
* @property array $emailIds
* @property Email[] $emails
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 2.0
*/
class OrderStatus extends Model
{
// Properties
// =========================================================================
/**
* @var int ID
*/
public $id;
/**
* @var string Name
*/
public $name;
/**
* @var string Handle
*/
public $handle;
/**
* @var string Color
*/
public $color = 'green';
/**
* @var int Sort order
*/
public $sortOrder;
/**
* @var bool Default status
*/
public $default;
/**
* @var boo Whether the order status is archived.
*/
public $isArchived = false;
/**
* @var \DateTime Archived Date
*/
public $dateArchived;
/**
* @var string UID
*/
public $uid;
// Public Methods
// =========================================================================
/**
* @return string
*/
public function __toString()
{
return (string)$this->name;
}
/**
* @return array
*/
public function rules()
{
return [
[['name', 'handle'], 'required'],
];
}
/**
* @return string
*/
public function getCpEditUrl(): string
{
return UrlHelper::cpUrl('commerce/settings/orderstatuses/' . $this->id);
}
/**
* @return array
*/
public function getEmailIds(): array
{
return array_column($this->getEmails(), 'id');
}
/**
* @return Email[]
*/
public function getEmails(): array
{
return $this->id ? Plugin::getInstance()->getEmails()->getAllEmailsByOrderStatusId($this->id) : [];
}
/**
* @return string
*/
public function getLabelHtml(): string
{
return sprintf('<span class="commerceStatusLabel"><span class="status %s"></span>%s</span>', $this->color, $this->name);
}
}
You can’t perform that action at this time.