<p>Having slept on it i thought it could be something to do with the order of the adjusters. Maybe Tax was applying to the price before my custom adjuster. So in the event i did the following:</p>

<pre><code>var_dump($event-&gt;types)
</code></pre>

<p>This told me that my custom adjuster was going to the bottom of this array. To resolve this i used the php function array_unshift to push it to the front of the array</p>

<pre><code>array_unshift($event-&gt;types,MyAdjuster::class);
</code></pre>

<p>This now gave me the following array:</p>

<pre><code>array(4) {
      [0]=&gt;
      string(18) "modules\MyAdjuster"
      [1]=&gt;
      string(33) "craft\commerce\adjusters\Shipping"
      [2]=&gt;
      string(33) "craft\commerce\adjusters\Discount"
      [3]=&gt;
      string(28) "craft\commerce\adjusters\Tax"
    }
</code></pre>

<p>As you can see the adjuster is at the front of the array and now the tax applies to the fee as required.</p>

CC BY-SA 4.0
2020-03-06T15:31:08.303Z
When you say "in the event" do you mean EVENT_REGISTER_ORDER_ADJUSTERS?
Darryl Hardin
CC BY-SA 4.0
2019-08-07T16:53:29.930Z
2019-08-07T16:53:29.930Z
Dean Sanderson
<p>I have created a custom adjuster, there is a surcharge per item if a customer has selected rush delivery. But i need to charge tax on that adjuster. Below is code:</p>

<pre><code>public function adjust(Order $order): array
{
    $adjustments = [];

    foreach ($order-&gt;getLineItems() as $item) {
        $adjustment = new OrderAdjustment;
        $adjustment-&gt;type = 'rush-delivery';
        $adjustment-&gt;name = 'Rush Delivery';
        $adjustment-&gt;description = 'Rush Delivery';
        $adjustment-&gt;sourceSnapshot = ['data' =&gt; 'value']; // This can contain information about how the adjustment came to be
        $adjustment-&gt;amount = 1;
        $adjustment-&gt;setOrder($order);
        $adjustment-&gt;setLineItem($item);

        $adjustments[] = $adjustment;
    }

    return $adjustments;
}
</code></pre>

<p>But tax is not added to the £1 i am adding here. How can i get tax to be added or calculated as included?</p>

<craft3><plugin-craftcommerce2>
Commerce 2 Adding tax to custom adjuster
# Commerce 2 Adding tax to custom adjuster

(Asked by: username_0 on 2019-08-06)

I have created a custom adjuster, there is a surcharge per item if a customer has selected rush delivery. But i need to charge tax on that adjuster. Below is code:
public function adjust(Order $order): array
{
    $adjustments = [];

    foreach ($order->getLineItems() as $item) {
        $adjustment = new OrderAdjustment;
        $adjustment->type = 'rush-delivery';
        $adjustment->name = 'Rush Delivery';
        $adjustment->description = 'Rush Delivery';
        $adjustment->sourceSnapshot = ['data' => 'value']; // This can contain information about how the adjustment came to be
        $adjustment->amount = 1;
        $adjustment->setOrder($order);
        $adjustment->setLineItem($item);

        $adjustments[] = $adjustment;
    }

    return $adjustments;
}

But tax is not added to the £1 i am adding here. How can i get tax to be added or calculated as included?

**Tags:** craft3, plugin-craftcommerce2


---

## 1 answers

### Answer by username_0 on 2019-08-07. Score: 3

Having slept on it i thought it could be something to do with the order of the adjusters. Maybe Tax was applying to the price before my custom adjuster. So in the event i did the following:
var_dump($event->types)

This told me that my custom adjuster was going to the bottom of this array. To resolve this i used the php function array_unshift to push it to the front of the array
array_unshift($event->types,MyAdjuster::class);

This now gave me the following array:
array(4) {
      [0]=>
      string(18) "modules\MyAdjuster"
      [1]=>
      string(33) "craft\commerce\adjusters\Shipping"
      [2]=>
      string(33) "craft\commerce\adjusters\Discount"
      [3]=>
      string(28) "craft\commerce\adjusters\Tax"
    }

As you can see the adjuster is at the front of the array and now the tax applies to the fee as required.

> **Comments:**
> **username_1**: When you say "in the event" do you mean EVENT_REGISTER_ORDER_ADJUSTERS?  

---

