Skip to main content
Subscriptions · Revision #2

What is the subscription order builder?

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:

\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:

\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

Parameter Type Description
$builder \Aero\Subscription\Pipelines\SubscriptionOrderBuilder The subscription order builder.
$next \Closure The next step in the order item builder.

Attributes

Attribute
Type Description
$subscription
\Aero\Subscription\Models\Subscription
The subscription being processed.
$originalOrder
\Aero\Cart\Models\Order
The original order associated with the subscription.
$order
\Aero\Cart\Models\Order The new order being created for the subscription