PHPackages                             lalalili/laravelshoppingcart - 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. lalalili/laravelshoppingcart

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

lalalili/laravelshoppingcart
============================

Shopping cart package for Laravel 11/12/13 with PHP 8.3+ support.

v14.0.2(2w ago)1898MITPHPPHP ^8.3CI passing

Since Jun 13Pushed 1w agoCompare

[ Source](https://github.com/lalalili/laravelshoppingcart)[ Packagist](https://packagist.org/packages/lalalili/laravelshoppingcart)[ RSS](/packages/lalalili-laravelshoppingcart/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (7)Dependencies (30)Versions (9)Used By (0)

lalalili/laravelshoppingcart
============================

[](#lalalililaravelshoppingcart)

Shopping cart package for Laravel 11/12/13 with PHP 8.3+ support.

Requirements
------------

[](#requirements)

- PHP `^8.3`
- Laravel `^11.0|^12.0|^13.0`

Installation
------------

[](#installation)

```
composer require lalalili/laravelshoppingcart:^14.0
```

Publish config:

```
php artisan vendor:publish --provider="Lalalili\\ShoppingCart\\ShoppingCartServiceProvider" --tag="config"
```

This publishes `config/shopping_cart.php`.

Quick start
-----------

[](#quick-start)

```
use Lalalili\ShoppingCart\Facades\ShoppingCartFacade;

ShoppingCartFacade::session('user-1')->add([
    'id' => 'sku-001',
    'name' => 'Sample Item',
    'price' => 100,
    'quantity' => 2,
    'attributes' => [],
]);

$total = ShoppingCartFacade::session('user-1')->getTotal();
```

Batch operations
----------------

[](#batch-operations)

Use batch APIs when copying or rebuilding carts from stored state. They keep the same validation and quantity semantics as `add()`/`remove()`, but persist once per batch.

```
ShoppingCartFacade::session('user-1')->addMany([
    ['id' => 'sku-001', 'name' => 'Sample Item', 'price' => 100, 'quantity' => 2],
    ['id' => 'sku-002', 'name' => 'Second Item', 'price' => 50, 'quantity' => 1],
]);

ShoppingCartFacade::session('user-1')->removeMany(['sku-001', 'sku-002']);
```

Repeated subtotal and total calls are cached for the lifetime of the cart instance and are invalidated automatically when items, conditions, session keys, or formatting options change.

Extension points
----------------

[](#extension-points)

v14.0 includes hooks for application-specific cart behavior:

```
return [
    'item_collection_class' => App\Support\CartItem::class,
    'associated_model_resolver' => App\Support\CartModelResolver::class,
    'rounding' => [
        'item_price_before_quantity' => 0,
        'line_subtotal' => ['precision' => 0, 'mode' => 'half_up'],
        'subtotal' => null,
        'total' => null,
    ],
];
```

`item_collection_class` must extend `Lalalili\ShoppingCart\ItemCollection`. `associated_model_resolver` may be a callable or implement `Lalalili\ShoppingCart\Contracts\AssociatedModelResolverInterface`. Rounding rules may be `null`, an integer precision, or `['precision' => int, 'mode' => 'half_up|half_down|half_even|half_odd']`.

Snapshots and total explanations
--------------------------------

[](#snapshots-and-total-explanations)

Use snapshots when a frontend, checkout review page, or regression test needs a stable cart payload.

```
$cart = ShoppingCartFacade::session('user-1');

$snapshot = $cart->snapshot();
$explain = $cart->explainTotals();
```

`snapshot()` includes items, cart conditions, context, subtotal, total, quantity, version, and hash. `explainTotals()` includes the item, subtotal, and total condition steps used to produce the final total. When pipelines have been run, `snapshot()` also includes their `changed`, `warnings`, and `metadata` results.

Checkout context and stale cart checks
--------------------------------------

[](#checkout-context-and-stale-cart-checks)

Context stores checkout-specific inputs without changing item rows.

```
$cart = ShoppingCartFacade::session('user-1')
    ->withContext([
        'customer_id' => 123,
        'channel' => 'web',
        'currency' => 'TWD',
        'coupon_codes' => ['WELCOME100'],
    ]);

$hash = $cart->hash();
$cart->assertHash($hash);
```

`assertHash()` throws `Lalalili\ShoppingCart\Exceptions\StaleCartException` when another tab, request, or device has changed the cart.

Cart pipelines
--------------

[](#cart-pipelines)

Pipelines let applications attach promotion, gift, validation, or checkout transformations without subclassing the cart.

```
return [
    'pipelines' => [
        'before_totals' => [
            App\Cart\Pipelines\ApplyPromotions::class,
        ],
        'before_checkout' => [
            App\Cart\Pipelines\ValidateInventory::class,
        ],
    ],
];
```

Pipeline classes implement `Lalalili\ShoppingCart\Contracts\CartPipelineInterface`. `before_totals` runs automatically before subtotal and total calculations. Other stages may be triggered with `runPipelines('before_checkout')`.

Optional Store API
------------------

[](#optional-store-api)

The package can expose a small JSON cart API, disabled by default:

```
return [
    'api' => [
        'enabled' => true,
        'require_hash' => false,
        'prefix' => 'cart',
        'middleware' => ['web'],
    ],
];
```

Available endpoints include `GET /cart`, `POST /cart/items`, `POST /cart/items/batch`, `PATCH /cart/items/{id}`, `DELETE /cart/items/{id}`, `DELETE /cart/items`, `POST /cart/conditions`, `PUT /cart/context`, and `DELETE /cart`. Mutating endpoints validate their payloads and accept an optional cart hash precondition through `If-Match`, `X-Cart-Hash`, `cart_hash`, or `hash`. A stale hash returns HTTP `409`; when `api.require_hash` is enabled, missing hashes return HTTP `428`.

Configuration key
-----------------

[](#configuration-key)

v14 uses `shopping_cart` config key.

```
config('shopping_cart.decimals');
```

v14.x compatibility promise
---------------------------

[](#v14x-compatibility-promise)

- `v14.x` is **non-breaking only**.
- Existing public API names stay stable in v14:
    - Facade: `ShoppingCartFacade`
    - Service provider: `ShoppingCartServiceProvider`
    - Container key: `shopping_cart`
    - Config key: `shopping_cart`
- Additive APIs such as `addMany()`, `removeMany()`, `snapshot()`, and `withContext()` may be introduced in v14 minor releases.
- Breaking changes are deferred to `v15`.

Breaking changes in v14.0.0
---------------------------

[](#breaking-changes-in-v1400)

- Config key changed from `lalalili_shopping_cart` to `shopping_cart`.
- Config publish target changed from `lalalili_shopping_cart.php` to `shopping_cart.php`.
- Environment variables changed from `LALALILI_SHOPPING_*` and `SHOPPING_*` to `SHOPPING_CART_*`.
- The old `lalalili_shopping_cart` config key is no longer read.

Testing and quality
-------------------

[](#testing-and-quality)

```
composer test
composer test:pest
composer analyse
```

Benchmark
---------

[](#benchmark)

```
composer bench
```

Latest local benchmark baseline (`v14.x`, PHP 8.4, synthetic data):

ItemsAdd (ms)Update (ms)getTotal x10 (ms)Peak memory (MB)10019.370.410.466.001,00090.953.662.128.0010,000900.0137.1423.7714.00Release flow
------------

[](#release-flow)

Release checklist is available at `.github/ISSUE_TEMPLATE/release-checklist.md`.

Standard flow:

`milestone close -> tag -> release -> packagist ping -> smoke check`

License
-------

[](#license)

MIT

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance98

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.1% 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 ~62 days

Recently: every ~27 days

Total

7

Last Release

14d ago

Major Versions

v12.0.0 → 13.0.02026-03-02

13.2.0 → 14.0.02026-05-10

PHP version history (2 changes)v12.0.0PHP &gt;=7.3

13.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d12612270f160b9b015d603ed637f88cfc5edd78f2e287b29ac9ae22a71e8f1?d=identicon)[lalalili](/maintainers/lalalili)

---

Top Contributors

[![darryldecode](https://avatars.githubusercontent.com/u/5498919?v=4)](https://github.com/darryldecode "darryldecode (137 commits)")[![ebisbe](https://avatars.githubusercontent.com/u/6747962?v=4)](https://github.com/ebisbe "ebisbe (22 commits)")[![lalalili](https://avatars.githubusercontent.com/u/7522570?v=4)](https://github.com/lalalili "lalalili (13 commits)")[![alhaji-aki](https://avatars.githubusercontent.com/u/19788708?v=4)](https://github.com/alhaji-aki "alhaji-aki (8 commits)")[![SimoTod](https://avatars.githubusercontent.com/u/8427737?v=4)](https://github.com/SimoTod "SimoTod (8 commits)")[![it-can](https://avatars.githubusercontent.com/u/644288?v=4)](https://github.com/it-can "it-can (5 commits)")[![frezno](https://avatars.githubusercontent.com/u/842148?v=4)](https://github.com/frezno "frezno (3 commits)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (3 commits)")[![saleem189](https://avatars.githubusercontent.com/u/75361545?v=4)](https://github.com/saleem189 "saleem189 (3 commits)")[![davidavz](https://avatars.githubusercontent.com/u/6774576?v=4)](https://github.com/davidavz "davidavz (2 commits)")[![belguinan](https://avatars.githubusercontent.com/u/19215568?v=4)](https://github.com/belguinan "belguinan (2 commits)")[![mateusjatenee](https://avatars.githubusercontent.com/u/10816999?v=4)](https://github.com/mateusjatenee "mateusjatenee (2 commits)")[![ahme-d](https://avatars.githubusercontent.com/u/9767569?v=4)](https://github.com/ahme-d "ahme-d (2 commits)")[![Beaudinn](https://avatars.githubusercontent.com/u/3606046?v=4)](https://github.com/Beaudinn "Beaudinn (2 commits)")[![sdunayer](https://avatars.githubusercontent.com/u/64154450?v=4)](https://github.com/sdunayer "sdunayer (1 commits)")[![aaronflorey](https://avatars.githubusercontent.com/u/948073?v=4)](https://github.com/aaronflorey "aaronflorey (1 commits)")[![Turaylon](https://avatars.githubusercontent.com/u/618998?v=4)](https://github.com/Turaylon "Turaylon (1 commits)")[![abdelazizib](https://avatars.githubusercontent.com/u/40918924?v=4)](https://github.com/abdelazizib "abdelazizib (1 commits)")[![AidasK](https://avatars.githubusercontent.com/u/2088484?v=4)](https://github.com/AidasK "AidasK (1 commits)")[![aimalamiri](https://avatars.githubusercontent.com/u/34779928?v=4)](https://github.com/aimalamiri "aimalamiri (1 commits)")

---

Tags

laravelecommercecartshopping cart

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lalalili-laravelshoppingcart/health.svg)

```
[![Health](https://phpackages.com/badges/lalalili-laravelshoppingcart/health.svg)](https://phpackages.com/packages/lalalili-laravelshoppingcart)
```

###  Alternatives

[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[propaganistas/laravel-disposable-email

Disposable email validator

6023.0M7](/packages/propaganistas-laravel-disposable-email)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[ultrono/laravelshoppingcart-1

Laravel 11 and above Shopping cart

1111.1k](/packages/ultrono-laravelshoppingcart-1)

PHPackages © 2026

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