offline-agency/oa-laravel-cart
A shopping cart package for Laravel that handles cart storage, item management, quantities, and totals, giving your app a ready-made foundation for adding products to the cart, updating quantities, and calculating prices without writing cart logic from scratch.
composer require offline-agency/laravel-cart.php artisan vendor:publish --provider="OfflineAgency\LaravelCart\CartServiceProvider"
php artisan migrate
use OfflineAgency\LaravelCart\Traits\HasCart;
class User extends Authenticatable
{
use HasCart;
}
config/cart.php first. Confirm the storage driver (session vs database), cart model, item model, the guest-transfer option, and — new in 4.2.0 — the tax allocation settings (rate source, inclusive vs exclusive pricing, rounding strategy, and whether tax is allocated per item or per cart).use OfflineAgency\LaravelCart\Facades\Cart;
Cart::add($product, 1);
$items = Cart::content();
$tax = Cart::tax(); // verify accessor name in your installed version
Cart facade methods, HasCart trait, package events, the published migrations, and — for 4.2.0 — the tax allocation classes and the cart recipe/executable definitions in src/. The two new areas to verify against your app are payable tax allocation (how per-line tax is computed and where it surfaces on the cart, items, and checkout totals) and executable cart recipes (how a named sequence of cart operations is defined, registered, and run).Cart::add(), Cart::update(), Cart::remove(), and Cart::clear() from there. This keeps checkout, product pages, and API endpoints consistent.DB::transaction(function () use ($cart) {
$order = Order::createFromCart($cart->content(), [
'tax_total' => $cart->tax(),
]);
// copy per-line allocated tax onto order items
});
// shape depends on the package API — verify the entry point in src/
Cart::recipe(StarterCartRecipe::class)->execute($user);
DB::transaction(fn () => Cart::recipe($recipe)->execute($user));
The package guarantees per-mutation atomicity; it does not give you a transaction boundary across the whole recipe plus your own writes.config/cart.php and explicitly trigger the transfer after authentication. A typical pattern is a listener on Laravel’s Login event or a small middleware:
public function handle(Login $event): void
{
Cart::transferGuestCart($event->user);
}
Verify the exact method name against the package API for your installed version, but the workflow is: guest cart exists in session, user logs in, transfer runs, authenticated user cart is merged. With 4.2.0, confirm how tax allocation behaves across the merge — merged lines should carry their own allocated tax, not inherit the destination cart's rate.Cart facade usage the same so application code does not depend on the driver — and make sure the custom driver can surface the tax allocation data the package expects.RefreshDatabase when verifying persistence, tax allocation, and transfer behavior. For unit tests, resolve the cart manager from the container and use a fresh session/store per test. Add at least one test asserting per-line tax + cart tax sums to the expected total for a multi-rate cart.php artisan config:clear
Re-publish the package config after a minor upgrade to see whether 4.2.0 added tax keys — but diff before overwriting your customisations.afterCommit behavior.How can I help you explore Laravel packages today?