<p>I solved this by overriding the routes set by craft commerce and extend the OrderController and the Order element.</p>

<p>This is not a good solution (I'm going upload this as a plugin) and if several plugins overwrite the same route, only the latest plugin will work.</p>

<p>If anyone have a proper solution I'll accept that. I'll leave this answer here in the meantime.</p>

<p><strong>Plugin::init()</strong></p>

<pre><code>    Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function (RegisterUrlRulesEvent $event) {
        $event-&gt;rules['commerce/orders'] = 'commerce-easy-order-management/orders/order-index';
        $event-&gt;rules['commerce/orders/&lt;orderId:\d+&gt;'] = 'commerce-easy-order-management/orders/edit-order';
        $event-&gt;rules['commerce/orders/action/&lt;orderId:\d+&gt;'] = 'commerce-easy-order-management/orders/order-action';
    });
</code></pre>

<p><strong>controllers\OrdersController</strong></p>

<pre><code>class OrdersController extends \craft\commerce\controllers\OrdersController
{
    /**
     * Index of Orders
     * Overwriting commerce/controllers/OrderController::actionOrderIndex()
     *
     * @return Response
     * @throws \Throwable
     */
    public function actionOrderIndex(): Response
    {
        // Remove all incomplete carts older than a certain date in config.
        Plugin::getInstance()-&gt;getCarts()-&gt;purgeIncompleteCarts();

        Craft::$app-&gt;view-&gt;registerCssFile('https://use.fontawesome.com/releases/v5.3.1/css/all.css');

        return $this-&gt;renderTemplate('commerce-easy-order-management/orders/_index');
    }
}
</code></pre>

<p><strong>elements\Order</strong></p>

<pre><code>class Order extends \craft\commerce\elements\Order
{
    /**
     * @inheritdoc
     */
    public function getTableAttributeHtml(string $attribute): string
    {
        if($attribute !== 'orderActions') return parent::getTableAttributeHtml($attribute);
        return 'MyActionHTML';
    }

    /**
     * @inheritdoc
     */
    protected static function defineTableAttributes(): array
    {
        $attributes = parent::defineTableAttributes();
        $attributes['orderActions'] = ['label' =&gt; Craft::t('commerce', 'Actions')];
        return $attributes;
    }
}
</code></pre>

<p><strong>templates/orders/_index.html</strong></p>

<pre><code>{% extends "_layouts/elementindex" %}

{% set title = "Orders"|t('commerce') %}
{% set docTitle = title~' - '~'Commerce' %}
{% set elementType = 'MY_NAMESPACE\\elements\\Order' %} 
{% set selectedTab = 'orders' %}
{% set selectedSubnavItem = "orders" %}
{% set bodyClass = (bodyClass is defined ? bodyClass~' ' : '') ~ "commerceorders     commerceordersindex" %}

{% do craft.app.view.registerTranslations('commerce', [
    "Total Revenue",
    "Last 7 days",
    "Last 30 days",
    "Last Week",
    "Last Month",
    "Custom Range",
    "Apply"
]) %}
</code></pre>

CC BY-SA 4.0
2018-12-20T12:19:33.730Z
2018-12-21T08:32:17.237Z
2018-12-21T08:32:17.237Z
Jørgen
<p>I need to add and/or change an attribute in the order table on <code>/admin/commerce/orders</code>.</p>

<p>The Order Element itself does not have a <code>EVENT_SET_TABLE_ATTRIBUTE_HTML</code>, and I've tried with variations like this:</p>

<pre><code>public function init()
{
    parent::init();
    Event::on(Element::class, Element::EVENT_SET_TABLE_ATTRIBUTE_HTML,[$this, 'setOrderStatusTableAttributeHtml']);
}

public function setOrderStatusTableAttributeHtml($event, $attribute)
{
    if ($event-&gt;element instanceof \craft\commerce\elements\Order &amp;&amp; $attribute == 'orderStatus') {
        return 'Changed';
    }
}
</code></pre>

<p>The event does not show up in the debug bar. I've also tried a <code>EVENT_INIT</code> with <code>die('died')</code> an that kills the execution, so my plugin is installed and loading.</p>

<plugin-craftcommerce><events>
Modify Order table in Control Panel
# Modify Order table in Control Panel

(Asked by: username_0 on 2018-12-18)

I need to add and/or change an attribute in the order table on /admin/commerce/orders.
The Order Element itself does not have a EVENT_SET_TABLE_ATTRIBUTE_HTML, and I've tried with variations like this:
public function init()
{
    parent::init();
    Event::on(Element::class, Element::EVENT_SET_TABLE_ATTRIBUTE_HTML,[$this, 'setOrderStatusTableAttributeHtml']);
}

public function setOrderStatusTableAttributeHtml($event, $attribute)
{
    if ($event->element instanceof \craft\commerce\elements\Order && $attribute == 'orderStatus') {
        return 'Changed';
    }
}

The event does not show up in the debug bar. I've also tried a EVENT_INIT with die('died') an that kills the execution, so my plugin is installed and loading.

**Tags:** plugin-craftcommerce, events


---

## 1 answers

### Answer by username_0 on 2018-12-20. Score: 1

I solved this by overriding the routes set by craft commerce and extend the OrderController and the Order element.
This is not a good solution (I'm going upload this as a plugin) and if several plugins overwrite the same route, only the latest plugin will work.
If anyone have a proper solution I'll accept that. I'll leave this answer here in the meantime.
Plugin::init()
    Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function (RegisterUrlRulesEvent $event) {
        $event->rules['commerce/orders'] = 'commerce-easy-order-management/orders/order-index';
        $event->rules['commerce/orders/'] = 'commerce-easy-order-management/orders/edit-order';
        $event->rules['commerce/orders/action/'] = 'commerce-easy-order-management/orders/order-action';
    });

controllers\OrdersController
class OrdersController extends \craft\commerce\controllers\OrdersController
{
    /**
     * Index of Orders
     * Overwriting commerce/controllers/OrderController::actionOrderIndex()
     *
     * @return Response
     * @throws \Throwable
     */
    public function actionOrderIndex(): Response
    {
        // Remove all incomplete carts older than a certain date in config.
        Plugin::getInstance()->getCarts()->purgeIncompleteCarts();

        Craft::$app->view->registerCssFile('https://use.fontawesome.com/releases/v5.3.1/css/all.css');

        return $this->renderTemplate('commerce-easy-order-management/orders/_index');
    }
}

elements\Order
class Order extends \craft\commerce\elements\Order
{
    /**
     * @inheritdoc
     */
    public function getTableAttributeHtml(string $attribute): string
    {
        if($attribute !== 'orderActions') return parent::getTableAttributeHtml($attribute);
        return 'MyActionHTML';
    }

    /**
     * @inheritdoc
     */
    protected static function defineTableAttributes(): array
    {
        $attributes = parent::defineTableAttributes();
        $attributes['orderActions'] = ['label' => Craft::t('commerce', 'Actions')];
        return $attributes;
    }
}

templates/orders/_index.html
{% extends "_layouts/elementindex" %}

{% set title = "Orders"|t('commerce') %}
{% set docTitle = title~' - '~'Commerce' %}
{% set elementType = 'MY_NAMESPACE\\elements\\Order' %} 
{% set selectedTab = 'orders' %}
{% set selectedSubnavItem = "orders" %}
{% set bodyClass = (bodyClass is defined ? bodyClass~' ' : '') ~ "commerceorders     commerceordersindex" %}

{% do craft.app.view.registerTranslations('commerce', [
    "Total Revenue",
    "Last 7 days",
    "Last 30 days",
    "Last Week",
    "Last Month",
    "Custom Range",
    "Apply"
]) %}


---

