PHPackages                             ksdev/shopping-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. ksdev/shopping-cart

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

ksdev/shopping-cart
===================

Shopping cart

0.2.6(10y ago)2112MITPHPPHP &gt;=5.3.0

Since Aug 1Pushed 10y ago2 watchersCompare

[ Source](https://github.com/ksdev-pl/shopping-cart)[ Packagist](https://packagist.org/packages/ksdev/shopping-cart)[ Docs](https://github.com/ksdev-pl/shopping-cart)[ RSS](/packages/ksdev-shopping-cart/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

Shopping Cart
=============

[](#shopping-cart)

[![Latest Version on Packagist](https://camo.githubusercontent.com/510ac5186967ebd31a1e939977ce2d98cdc963a2691cb9e2db1380669e01bb61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b736465762f73686f7070696e672d636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ksdev/shopping-cart)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/903291685ef5f91b2cf39582c9c4efa460b9b1a1bdec8ef1c2f24bed359387cd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6b736465762d706c2f73686f7070696e672d636172742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ksdev-pl/shopping-cart)[![Coverage Status](https://camo.githubusercontent.com/02ca484e39e2b5861cabacbf9fc3dead5dd9640e96785ea2473c1f93f5b58d92/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6b736465762d706c2f73686f7070696e672d636172742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ksdev-pl/shopping-cart/code-structure)[![Quality Score](https://camo.githubusercontent.com/2d4c963b6039aa963b1fb9cf2e669db2ae82cd9c893561b30e5c6850c9aa3e67/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6b736465762d706c2f73686f7070696e672d636172742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/ksdev-pl/shopping-cart)

Original source:  by Larry Ullman. See the article for description and compare source code for changes.

Install
-------

[](#install)

Via Composer

```
$ composer require ksdev/shopping-cart
```

Usage
-----

[](#usage)

```
use Ksdev\ShoppingCart\Cart;
use Ksdev\ShoppingCart\Currency;
use Ksdev\ShoppingCart\Item;

$cart = new Cart(new Currency('PLN'));

$tax = '23.00';                                 // Tax is optional

$item1 = new Item('SKU1', 'Item 1', '100.00', $tax);
$item2 = new Item('SKU2', 'Item 2', '200.00', $tax);
$item3 = new Item('SKU3', 'Item 3', '300.00', $tax);

$cart->addItem($item1);
$cart->addItem($item2);
$cart->addItem($item3);

if (!$cart->isEmpty()) {
    foreach ($cart as $arr) {
        $item = $arr['item'];
        var_dump($item->getSku());              // E.g. string(4) "SKU1"
        var_dump($item->getName());             // E.g. string(6) "Item 1"
        var_dump($item->getPrice());            // E.g. string(6) "100.00"
        var_dump($item->getTax());              // E.g. string(5) "23.00"
        var_dump($arr['qty']);                  // E.g. int(1)
    }
}

var_dump($cart->total());                       // string(6) "600.00"
var_dump($cart->getCurrency()->getCode());      // string(3) "PLN"

$item4 = new Item('SKU1', 'Item 1', '100.00', $tax);  // Same as $item1
$cart->addItem($item4);

var_dump($cart->total());                       // string(6) "700.00"
var_dump($cart->count());                       // int(4); also: count($cart)
var_dump($cart->countUnique());                 // int(3)

$cart->updateItem($item2, 3);                   // 3 is the new quantity

var_dump($cart->count());                       // int(6)
var_dump($cart->countUnique());                 // int(3)

$cart->updateItem($item2, 0);                   // Removes the item from the cart

var_dump($cart->count());                       // int(3)
var_dump($cart->countUnique());                 // int(2)

$cart->deleteItem($item1);                      // Removes the item from the cart

var_dump($cart->count());                       // int(1)
var_dump($cart->countUnique());                 // int(1)

var_dump($cart->getItem('SKU3'));               // Get item by Stock Keeping Unit
/*
    array(2) {
        'item' => class Ksdev\ShoppingCart\Item#270 (3) {
            protected $sku   => string(4) "SKU3"
            protected $name  => string(6) "Item 3"
            protected $price => string(6) "300.00"
            protected $tax   => string(5) "23.00"
        }
        'qty' => int(1)
    }
*/
```

Testing
-------

[](#testing)

```
$ composer test
```

Credits
-------

[](#credits)

- Larry Ullman

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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 ~1 days

Total

5

Last Release

3939d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f28ff32516124507bad6fd9c54b0b8c7d1df95e0053166f912b81dfcc7a7c07a?d=identicon)[ksdev](/maintainers/ksdev)

---

Top Contributors

[![ksdev-pl](https://avatars.githubusercontent.com/u/4216259?v=4)](https://github.com/ksdev-pl "ksdev-pl (14 commits)")

---

Tags

phpshopping-cartcartshopping cartksdev

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ksdev-shopping-cart/health.svg)

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

###  Alternatives

[extcode/cart

Shopping Cart(s) for TYPO3

57119.3k14](/packages/extcode-cart)[wearepixel/laravel-cart

A cart implementation for Laravel

1310.5k](/packages/wearepixel-laravel-cart)[ultrono/laravelshoppingcart-1

Laravel 11 and above Shopping cart

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

PHPackages © 2026

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