PHPackages                             andreilungeanu/simple-cart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. andreilungeanu/simple-cart

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

andreilungeanu/simple-cart
==========================

A simple cart package for Laravel applications

v1.6.0(3mo ago)025[3 PRs](https://github.com/andreilungeanu/simple-cart/pulls)MITPHPPHP ^8.2CI passing

Since Apr 25Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/andreilungeanu/simple-cart)[ Packagist](https://packagist.org/packages/andreilungeanu/simple-cart)[ Docs](https://github.com/andreilungeanu/simple-cart)[ GitHub Sponsors]()[ RSS](/packages/andreilungeanu-simple-cart/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (12)Versions (14)Used By (0)

Simple Cart Laravel Package
===========================

[](#simple-cart-laravel-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/be5b69524b9af1543977562a0cec3e8fa2451d47da780b83a58f0debdb634708/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e647265696c756e6765616e752f73696d706c652d636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andreilungeanu/simple-cart)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b647c96f11251e1cc0c40a0bb184a831595765192e65c5436da2eae821e3ab07/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e647265696c756e6765616e752f73696d706c652d636172742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/andreilungeanu/simple-cart/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/6f4a9bdbf0450fe114fd07950ea1e5704b2c64dd944b779328b86a87ca6c2aa6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e647265696c756e6765616e752f73696d706c652d636172742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/andreilungeanu/simple-cart/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/82709becfffbe2495b8a2a1181273f11fee84c3ec000366bd23e0bcb1eed16ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647265696c756e6765616e752f73696d706c652d636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andreilungeanu/simple-cart)

**Modern Laravel shopping cart package with clean architecture**

> **📖 For detailed documentation, examples, and advanced usage, see [DOCUMENTATION.md](DOCUMENTATION.md)**

🎯 Features
----------

[](#-features)

- ✅ **Event-Driven Design** - Comprehensive listeners for cart lifecycle events
- ✅ **Advanced Calculations** - Dynamic tax system, flexible shipping, flexible discount system (fixed, percentage, free shipping with conditional logic)
- ✅ **Multiple Cart Instances** - Proper user/session isolation and state management
- ✅ **Service-Based API** - Clean service layer for cart operations
- ✅ **Database Persistence** - Reliable storage with automatic expiration handling

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require andreilungeanu/simple-cart
```

Publish and run migrations:

```
php artisan vendor:publish --tag="simple-cart-migrations"
php artisan migrate
```

Optionally publish the configuration:

```
php artisan vendor:publish --tag="simple-cart-config"
```

🚀 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

```
use AndreiLungeanu\SimpleCart\Facades\Cart;

// Create cart for user
$cart = Cart::create(userId: 123);

// Add items to cart
Cart::addItem($cart, [
    'product_id' => 'prod_1',
    'name' => 'Gaming Laptop',
    'price' => 1299.99,
    'quantity' => 1,
    'category' => 'electronics'
]);

Cart::addItem($cart, [
    'product_id' => 'prod_2',
    'name' => 'Wireless Mouse',
    'price' => 25.50,
    'quantity' => 2
]);

// Apply tax
Cart::applyTax($cart, [
    'code' => 'VAT_UK',
    'rate' => 0.20,
    'apply_to_shipping' => true
]);

// Apply discount
Cart::applyDiscount($cart, [
    'code' => 'SAVE50',
    'type' => 'fixed',
    'value' => 50,
    'conditions' => ['minimum_amount' => 100]
]);

// Apply shipping
Cart::applyShipping($cart, [
    'method_name' => 'Express Shipping',
    'cost' => 15.99,
    'carrier' => 'UPS'
]);

// Get calculations
$subtotal = Cart::calculateSubtotal($cart);    // 1350.99
$shipping = Cart::calculateShipping($cart);    // 15.99 (or 0 if free shipping)
$tax = Cart::calculateTax($cart);              // Based on applied tax config
$total = Cart::calculateTotal($cart);          // Final total with all calculations

echo "Final Total: $" . $total;
```

### Cart Summary

[](#cart-summary)

```
// Get complete cart overview
$summary = Cart::getCartSummary($cart);
/*
[
    'id' => 'cart-uuid',
    'item_count' => 3,
    'subtotal' => 1350.99,
    'shipping' => 15.99,
    'tax' => 270.20,
    'discounts' => 50.00,
    'total' => 1586.18,
    'status' => 'active',
    'expires_at' => '2025-10-07T12:00:00.000000Z'
]
*/
```

### Cart merge stratery on login

[](#cart-merge-stratery-on-login)

When a user logs in and both a guest session cart and a user cart exist, you can control behavior via `login_cart_strategy` (env: `CART_ON_LOGIN_CART_STRATEGY`). Options: `merge` (default), `guest`, `user`.

For details, see the documentation section “Cart Merge Strategy on Login”.

🔧 Key Features Overview
-----------------------

[](#-key-features-overview)

### Dynamic Tax System

[](#dynamic-tax-system)

- **Priority-based rates**: Item-specific &gt; Category &gt; Type &gt; Default
- **Flexible conditions**: Support for any tax scenario
- **API integration ready**: Perfect for external tax services

### Advanced Discounts

[](#advanced-discounts)

- **Multiple types**: Percentage, fixed amount, free shipping
- **Conditional logic**: Minimum amounts, item requirements, categories
- **Stacking support**: Configure multiple discount behavior

### Flexible Shipping

[](#flexible-shipping)

- **Dynamic rates**: Your app provides shipping data
- **Free shipping**: Threshold-based or discount-based
- **Carrier integration**: Store any shipping method data

### Event-Driven Architecture

[](#event-driven-architecture)

All cart operations dispatch events for:

- Analytics tracking
- Inventory management
- Cache invalidation
- Custom business logic

📖 Complete Documentation
------------------------

[](#-complete-documentation)

For comprehensive documentation including:

- **Detailed API reference** with all methods and parameters
- **Advanced tax scenarios** (EU VAT, US State tax, API integration)
- **Conditional discount patterns** (percentage, fixed amount, free shipping; quantity/amount conditions)
- **Event handling examples** (analytics, inventory, notifications)
- **Performance optimization** tips and caching strategies
- **Security best practices** and error handling
- **Complete usage examples** for real-world scenarios

**👉 See [DOCUMENTATION.md](DOCUMENTATION.md)**

⚡ Configuration
---------------

[](#-configuration)

Basic configuration in `config/simple-cart.php`:

```
return [
    'storage' => [
        'ttl_days' => 30,              // Cart expiration
    ],
    'shipping' => [
        'free_shipping_threshold' => 100.00,  // Free shipping over $100
    ],
    'discounts' => [
        'allow_stacking' => false,     // Allow multiple discount codes
        'max_discount_codes' => 3,     // Maximum discount codes per cart
    ],
];
```

🧹 Maintenance
-------------

[](#-maintenance)

Clean up expired carts:

```
# Manual cleanup
php artisan simple-cart:cleanup

# Scheduled cleanup (add to Kernel.php)
$schedule->command('simple-cart:cleanup --force')->daily();
```

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

---

**Need help?** Check the [complete documentation](DOCUMENTATION.md) or create an issue on GitHub.

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance86

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Total

8

Last Release

103d ago

PHP version history (2 changes)v1.0.0PHP ^8.3

v1.4.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6858b95ca04a488da5ac7ddf7970b734ea42a4982a378532cd7c7ee23a5429ac?d=identicon)[andreilungeanu](/maintainers/andreilungeanu)

---

Top Contributors

[![andreilungeanu](https://avatars.githubusercontent.com/u/95976259?v=4)](https://github.com/andreilungeanu "andreilungeanu (20 commits)")

---

Tags

cartlaravelpackagelaravelsimple cartAndrei Lungeanu

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/andreilungeanu-simple-cart/health.svg)

```
[![Health](https://phpackages.com/badges/andreilungeanu-simple-cart/health.svg)](https://phpackages.com/packages/andreilungeanu-simple-cart)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M626](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
