# What is the subscription order builder?

The Subscription Order Builder runs whenever a subscription is processed and requires a new order. It creates the new order based on the original order associated with the subscription.

For example, you can add a flag to every order created by a subscription.

First add a setting to the `admin` group:

```php
\Aero\Common\Facades\Settings::group('acme', function (\Aero\Common\Settings\SettingGroup $group) {
    $group->eloquent('subscription_flag', \Aero\Common\Models\Flag::class)->dontLoadModel()->section('Orders');
});
```

The `SubscriptionOrderBuilder` can then use this setting to attach the flag to the new order:

```php
\Aero\Subscription\Pipelines\SubscriptionOrderBuilder::extend(function (\Aero\Subscription\Pipelines\SubscriptionOrderBuilder $builder, \Closure $next) {
    $flagId = setting('acme.subscription_flag');

    if (! is_int($flagId)) {
        return $next($builder);
    }

    $builder->order->flags()->attach($flagId);

    return $next($builder);
});
```

---

### Parameters

<table border="1" id="bkmrk-parameter-type-descr" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col></colgroup><tbody><tr><td>**Parameter**</td><td>**Type**</td><td>**Description**</td></tr><tr><td>`$builder`</td><td>`\Aero\Subscription\Pipelines\SubscriptionOrderBuilder`</td><td>The subscription order builder.</td></tr><tr><td>`$next`</td><td>`\Closure`</td><td>The next step in the order item builder.</td></tr></tbody></table>

### Attributes

<table border="1" id="bkmrk-attribute-type-descr" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 33.3333%;"></col><col style="width: 33.3333%;"></col><col style="width: 33.3333%;"></col></colgroup><tbody><tr><td>**Attribute**  
</td><td>**Type**</td><td>**Description**</td></tr><tr><td>`$subscription`  
</td><td>`\Aero\Subscription\Models\Subscription`  
</td><td>The subscription being processed.</td></tr><tr><td>`$originalOrder`  
</td><td>`\Aero\Cart\Models\Order`  
</td><td>The original order associated with the subscription.</td></tr><tr><td>`$order`  
</td><td>`\Aero\Cart\Models\Order`</td><td>The new order being created for the subscription</td></tr></tbody></table>