<p>Can you try this?</p>
<pre><code>use craft\commerce\models\OrderAdjustment;

$adjustment = new OrderAdjustment();

$adjustment-&gt;setOrder($order); // $order - craft\commerce\elements\Order;
</code></pre>

CC BY-SA 4.0
2022-10-20T14:39:09.087Z
yeah no go. pretty sure `type` is also required, but yeah bare minimum: `setOrder` and `type` still does not add the adjustment to the order only.
Steve Mock
CC BY-SA 4.0
2022-10-20T15:05:51.717Z
@SteveMock That's weird

You have at the very beginning: `$adjustments = [];` ?

And in the end:

`$adjustments[] = $adjustment;`

`return $adjustments;`
RomanAvr
CC BY-SA 4.0
2022-10-20T18:08:43.633Z
that's right. the class fires `update` successfully. would it matter that this is a [sprig][https://putyourlightson.com/plugins/sprig] cart update?
Steve Mock
CC BY-SA 4.0
2022-10-21T05:56:27.340Z
I guess that yes
RomanAvr
CC BY-SA 4.0
2022-10-20T12:03:22.610Z
2022-10-20T12:03:22.610Z
RomanAvr
<p>Registering like so and all is well.</p>
<pre><code>Event::on(
   OrderAdjustments::class,
   OrderAdjustments::EVENT_REGISTER_ORDER_ADJUSTERS,
   function(RegisterComponentTypesEvent $event) {
         $event-&gt;types[] = Freebie::class;
   }
 );
</code></pre>
<p>Per the docs (bolds mine):</p>
<blockquote>
<p>Each of those models may be applied to the order <strong>or</strong> one of its line
items.</p>
<p>An adjustment model always belongs to an order, but can <strong>optionally</strong>
belong to a line item.</p>
</blockquote>
<p>We've set up according to this [example here][1] which demonstrates looping through line items and adding the adjuster to each item. All good so far.</p>
<p><em>But how might we add an adjuster to only the order?</em></p>
<p>If we take the adjustment code out of the loop )as in the example linked above) and leave off the <code>$adjustment-&gt;setLineItem($item);</code>, the model does not appear in <code>cart.adjustments</code> nor <code>cart.orderAdjustments</code></p>
<pre><code>Craft CMS 3.7.50 [PRO]
Commerce 3.4.15 [PRO]


  [1]: https://craftcms.com/docs/commerce/3.x/extend/adjusters.html#designating-an-order-and-line-item
</code></pre>

<plugin-craftcommerce><ordering><adjusters>
How To Designate Adjuster on Order Only
# How To Designate Adjuster on Order Only

(Asked by: username_0 on 2022-10-19)

Registering like so and all is well.
Event::on(
   OrderAdjustments::class,
   OrderAdjustments::EVENT_REGISTER_ORDER_ADJUSTERS,
   function(RegisterComponentTypesEvent $event) {
         $event->types[] = Freebie::class;
   }
 );

Per the docs (bolds mine):

Each of those models may be applied to the order or one of its line
items.
An adjustment model always belongs to an order, but can optionally
belong to a line item.

We've set up according to this [example here][1] which demonstrates looping through line items and adding the adjuster to each item. All good so far.
But how might we add an adjuster to only the order?
If we take the adjustment code out of the loop )as in the example linked above) and leave off the $adjustment->setLineItem($item);, the model does not appear in cart.adjustments nor cart.orderAdjustments
Craft CMS 3.7.50 [PRO]
Commerce 3.4.15 [PRO]


  [1]: https://craftcms.com/docs/commerce/3.x/extend/adjusters.html#designating-an-order-and-line-item

**Tags:** plugin-craftcommerce, ordering, adjusters


---

## 1 answers

### Answer by username_1 on 2022-10-20. Score: 1

Can you try this?
use craft\commerce\models\OrderAdjustment;

$adjustment = new OrderAdjustment();

$adjustment->setOrder($order); // $order - craft\commerce\elements\Order;

> **Comments:**
> **username_0**: yeah no go. pretty sure `type` is also required, but yeah bare minimum: `setOrder` and `type` still does not add the adjustment to the order only.  
> **username_1**: @SteveMock That's weird  You have at the very beginning: `$adjustments = [];` ?  And in the end:  `$adjustments[] = $adjustment;`  `return $adjustments;`  
> **username_0**: that's right. the class fires `update` successfully. would it matter that this is a [sprig][https://putyourlightson.com/plugins/sprig] cart update?  
> **username_1**: I guess that yes  

---

