OrderElementTrait

Type
Trait
Namespace
craft\commerce\elements\traits
Implemented by
craft\commerce\elements\Order

View source (opens new window)

# Public Methods

Method Description
find() Creates an \ElementQueryInterface instance for query purpose.
getFieldLayout() Returns the field layout used by this element.
getSearchKeywords() Returns the search keywords for a given search attribute.
hasContent() Returns whether elements of this type will be storing any data in the content table (titles or custom fields).
prepElementQueryForTableAttribute() Preps the element criteria for a given table attribute

# find()

Creates an \ElementQueryInterface instance for query purpose.

The returned \ElementQueryInterface instance can be further customized by calling methods defined in \ElementQueryInterface before one() or all() is called to return populated \ElementInterface instances. For example,

// Find the entry whose ID is 5
$entry = Entry::find()->id(5)->one();
// Find all assets and order them by their filename:
$assets = Asset::find()
    ->orderBy('filename')
    ->all();

If you want to define custom criteria parameters for your elements, you can do so by overriding this method and returning a custom query class. For example,

class Product extends Element
{
    public static function find()
    {
        // use ProductQuery instead of the default ElementQuery
        return new ProductQuery(get_called_class());
    }
}

You can also set default criteria parameters on the ElementQuery if you don’t have a need for a custom query class. For example,

class Customer extends ActiveRecord
{
    public static function find()
    {
        return parent::find()->limit(50);
    }
}

View source (opens new window)

Returns

craft\commerce\elements\db\OrderQuery – The newly created \OrderQuery instance.

# getFieldLayout()

Returns the field layout used by this element.

View source (opens new window)

Returns

craft\models\FieldLayout (opens new window), null (opens new window)

# getSearchKeywords()

Returns the search keywords for a given search attribute.

View source (opens new window)

Arguments

Returns

string (opens new window)

# hasContent()

Returns whether elements of this type will be storing any data in the content table (titles or custom fields).

View source (opens new window)

Returns

boolean (opens new window) – Whether elements of this type will be storing any data in the content table.

# prepElementQueryForTableAttribute()

Preps the element criteria for a given table attribute

View source (opens new window)

Arguments

# Protected Methods

Method Description
defineActions() Defines the available element actions for a given source.
defineDefaultTableAttributes() Returns the list of table attribute keys that should be shown by default.
defineExporters() Defines the available element exporters for a given source.
defineSearchableAttributes() Defines which element attributes should be searchable.
defineSortOptions() Returns the sort options for the element type.
defineSources() Defines the sources that elements of this type may belong to.
defineTableAttributes() Defines all of the available columns that can be shown in table views.
htmlAttributes() Returns any attributes that should be included in the element’s DOM representation in the control panel.
tableAttributeHtml() Returns the HTML that should be shown for a given attribute in Table View.

# defineActions()

Defines the available element actions for a given source.

View source (opens new window)

Arguments

Returns

array (opens new window) – The available element actions.

# defineDefaultTableAttributes()

Returns the list of table attribute keys that should be shown by default.

View source (opens new window)

Arguments

Returns

string (opens new window)[] – The table attributes.

# defineExporters()

Defines the available element exporters for a given source.

View source (opens new window)

Arguments

Returns

array (opens new window) – The available element exporters

# defineSearchableAttributes()

Defines which element attributes should be searchable.

View source (opens new window)

Returns

string (opens new window)[] – The element attributes that should be searchable

# defineSortOptions()

Returns the sort options for the element type.

View source (opens new window)

Returns

array (opens new window) – The attributes that elements can be sorted by

# defineSources()

Defines the sources that elements of this type may belong to.

View source (opens new window)

Arguments

Returns

array (opens new window) – The sources.

# defineTableAttributes()

Defines all of the available columns that can be shown in table views.

View source (opens new window)

Returns

array (opens new window) – The table attributes.

# htmlAttributes()

Returns any attributes that should be included in the element’s DOM representation in the control panel.

View source (opens new window)

Arguments

Returns

array (opens new window)

# tableAttributeHtml()

Returns the HTML that should be shown for a given attribute in Table View.

This method can be used to completely customize what actually shows up within the table’s body for a given attribute, rather than simply showing the attribute’s raw value.

For example, if your elements have an email attribute that you want to wrap in a mailto: link, your getTableAttributesHtml() method could do this:

switch ($attribute) {
    case 'email':
        return $this->email ? Html::mailto(Html::encode($this->email)) : '';
    // ...
}
return parent::tableAttributeHtml($attribute);

WARNING

All untrusted text should be passed through Html::encode() to prevent XSS attacks.

By default the following will be returned:

  • If the attribute name is link or uri, it will be linked to the front-end URL.
  • If the attribute is a custom field handle, it will pass the responsibility off to the field type.
  • If the attribute value is a DateTime (opens new window) object, the date will be formatted with a localized date format.
  • For anything else, it will output the attribute value as a string.

View source (opens new window)

Arguments

Returns

string (opens new window) – The HTML that should be shown for a given attribute in Table View.

Throws