What is the cart item builder?

The cart item builder is run whenever an item is added to the cart. It builds the item from the request data.

For example, you can add a gift wrap option to an item when the variant has gift wrapping enabled.

First, define a setting on the variant to control whether gift wrapping is available:

\Aero\Catalog\Models\Variant::settings(function (\Aero\Common\Settings\ModelSettingGroup $group) {
    $group->boolean('has_gift_wrap')->default(false);
});

The CartItemBuilder can then use this setting to add the gift wrap option:

\Aero\Store\Pipelines\CartItemBuilder::extend(function (\Aero\Cart\CartItem $item, \Closure $next) {
    if ($item->model->setting('has_gift_wrap')) {
        $item->addOption(
            \Aero\Cart\CartItemOption::create('Gift Wrap')
        );
    }
    
    return $next($item);
});

Parameters

Parameter Type Description
$item \Aero\Cart\CartItem The cart item being built.
$next \Closure The next step in the cart item builder.



Revision #3
Created 2026-09-18 06:36:31 UTC by Ethan Payne
Updated 2026-10-02 12:57:46 UTC by Ethan Payne