Looking to hire Laravel developers? Try LaraJobs

laravel-cart maintained by itmosoft

Description
A reusable Laravel shopping cart package with persistent carts, items, quantity management, and price snapshots. Supports Laravel 12 and 13.
Last update
2026/11/04 14:14 (dev-main)
License
Links
Downloads
0

Comments
comments powered by Disqus

ITMOSOFT Laravel Cart

Persistent shopping carts for Laravel 12 and 13 / PHP 8.3+.

Features

  • Persistent user and guest/session carts
  • Polymorphic cart items: any Eloquent model can be added
  • Quantity updates, item removal, and cart clearing
  • Item option variants kept as separate cart lines
  • Unit-price and line-total snapshots
  • Configurable currency, table prefix, models, and limits
  • Transactional cart writes and row-level locking

Install

composer require itmosoft/laravel-cart
php artisan vendor:publish --tag=itmosoft-cart-config
php artisan migrate

Create a cart

use ItmoSoft\Cart\Services\CartManager;

$manager = app(CartManager::class);

$cart = $manager->create(
    userId: auth()->id(),
    currency: 'USD',
);

For a guest cart, pass a session identifier instead:

$cart = $manager->create(sessionId: session()->getId());

Add an item

$item = $manager->add(
    cart: $cart,
    item: $product,
    quantity: 2,
    unitPrice: $resolvedPrice,
    options: ['size' => 'M', 'color' => 'navy'],
    priceSnapshot: ['source' => 'catalog', 'unit_price' => $resolvedPrice],
);

If unitPrice is omitted, the manager reads the model's price attribute. In production, pass the already-resolved price from your pricing layer. The package stores a price snapshot; it does not reprice or reserve inventory.

Manage cart

$manager->setQuantity($item, 3);
$manager->remove($item);
$manager->clear($cart);
$subtotal = $manager->subtotal($cart);

Integration boundaries

  • Product Catalog supplies product models; the cart accepts any Eloquent model.
  • Pricing should resolve the price before adding/updating a line.
  • Promotions and Tax are applied by the checkout/pricing orchestration layer; this package intentionally does not calculate discounts or tax.
  • Inventory is not reserved by adding an item. Reservation belongs to checkout/order orchestration.
  • This package does not create orders, process payments, or calculate shipping.

Testing

composer install
vendor/bin/phpunit

License

MIT.