Overview
Every operationLunar\Core\Models\Cart performs — adding a line, setting a shipping option, creating an order — is a one-line delegation from a verb method on the model to an action contract resolved from the container. Swapping behavior means binding a different implementation of that contract in a service provider; the verb picks it up automatically.
Cart action contracts
Lunar\Core\ActionServiceProvider’s $actions map is the canonical list of swappable action seams. The cart-related entries, each a Lunar\Core\Contracts\Actions\Carts\* interface bound to its Lunar\Core\Actions\Carts\* default implementation:
Rebind a contract from a consumer’s own service provider:
Config-string class substitution (
config('lunar.*', SomeClass::class)) is not used for these seams — the contract is bound in the container, and a consumer swaps it there. Do not add a config key to point at a custom class.Calculation pipelines
Cart totals are calculated by running the cart through an ordered list of pipeline classes, and cart lines through a second list. Both lists live inconfig/lunar/cart.php, as ordered lists rather than single-implementation swaps:
handle(Cart $cart, Closure $next): mixed; a cart line pipe implements the same shape against CartLine.
Validators
Cart::add(), updateLine(), remove(), addAddress(), setShippingOption(), and createOrder() each run a list of validators, configured the same way, in config/lunar/cart.php:
Lunar\Core\Validation\BaseValidator:
config/lunar/cart.php:
Lunar\Core\Exceptions\Carts\CartException is thrown. Errors are accessed the same way as Laravel’s own validation responses:
Cart line modifiers
A cart line unit price and subtotal can be adjusted just after it is calculated, using aLunar\Core\Modifiers\CartLineModifier:
CartLineModifier also exposes calculating() and calculated() hooks. Register an instance with the Lunar\Core\Modifiers\CartLineModifiers collection, resolved from the container:
Overriding order creation
Cart::createOrder() delegates to Contracts\Carts\CreatesOrder, which in turn runs the order through the pipeline configured in config/lunar/orders.php. See Extending Orders for the order-side pipeline and action contracts.