What is the order item builder?
The order item builder is run whenever a cart item is transformed into an order item. It builds the order item data from the cart item.
For example, you can add a custom attribute to the order item:
\Aero\Cart\OrderItemBuilder::extend(function (\Aero\Cart\OrderItemBuilder $builder, \Closure $next) {
$cartItem = $builder->item();
$builder->setAttributes([
'acme' => $cartItem->meta->get('acme'),
]);
return $next($builder);
});
Parameters
| Parameter | Type | Description |
$builder |
\Aero\Cart\OrderItemBuilder |
The order item builder. |
$next |
\Closure |
The next step in the order item builder. |
Methods
| Method | Description |
item() |
Returns the cart item being transformed. |
order() |
Returns the order that the order item will be added to once transformed. |
setAttribute(string $key, $value) |
Sets an attribute to be added to the order item. |
setAttributes(array $attributes) |
Sets attributes to be added to the order item (merges them with existing attributes). |
getAttribute(string $key) |
Returns the attribute corresponding to |
getAttributes() |
Returns the array of attributes to be set on the order item |