PHPackages                             endrilala/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. [Payment Processing](/categories/payments)
4. /
5. endrilala/cart

ActiveLibrary[Payment Processing](/categories/payments)

endrilala/cart
==============

Shopping cart classes

1.0(9mo ago)01MITPHPPHP &gt;=5.4.0

Since Aug 11Pushed 9mo agoCompare

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

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Cart \[WIP\]
============

[](#cart-wip)

Framework independent cart abstraction library.

[![Travis](https://camo.githubusercontent.com/3f06e6e1b3f54cb9592e975f2b35ade22ac6ab74a0316cd35836f57d2dddf5b0/68747470733a2f2f6170692e7472617669732d63692e6f72672f656e6472696c616c612f636172742e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/3f06e6e1b3f54cb9592e975f2b35ade22ac6ab74a0316cd35836f57d2dddf5b0/68747470733a2f2f6170692e7472617669732d63692e6f72672f656e6472696c616c612f636172742e7376673f6272616e63683d6d6173746572)[![CodeClimate](https://camo.githubusercontent.com/907da9879f331ad35069b42c316bf1e78c04749a88a90ceb49fbea85aa171ad2/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f656e6472696c616c612f636172742f6261646765732f6770612e737667)](https://camo.githubusercontent.com/907da9879f331ad35069b42c316bf1e78c04749a88a90ceb49fbea85aa171ad2/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f656e6472696c616c612f636172742f6261646765732f6770612e737667)[![Test Coverage](https://camo.githubusercontent.com/e5d6fcb8c05eeec37d6d8b147584bf4173ff7dfc3585b186960854945f6a24d4/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f656e6472696c616c612f636172742f6261646765732f636f7665726167652e737667)](https://camo.githubusercontent.com/e5d6fcb8c05eeec37d6d8b147584bf4173ff7dfc3585b186960854945f6a24d4/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f656e6472696c616c612f636172742f6261646765732f636f7665726167652e737667)

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

[](#installation)

Install the package through composer by running `composer require endrilala/cart`.

Otherwise just include the `endrilala\Cart` folder in your project and `require 'endrilala/Cart/autoload.php'`

Usage
-----

[](#usage)

Upon creation the cart class accepts a `CartPersistentInterface` which will supply the persistence mechanisms to the storage of your choice. Included are Array(most frequently used on $\_SESSION superglobal) and File storages.

To add new storage types(such as database) implement a the needed interface and hook the new class into your data.

```
// Basic usage where we store the cart in the $_SESSION variable
$cart = new Cart(new ArrayPersistenceStrategy($_SESSION, 'cart_data'));
```

### Adding items

[](#adding-items)

```
$data = ['name' => 'T Shirt', 'color' => 'red'];
$item = new CartItem($identifier = 'PRODUCT_CODE', $price = 10, $quantity = 1, $data);
$item->setVatIncluded(true);
$item->setVatRate(20);

$cart->add($cartItem);
$cart->save();
```

### Updating items

[](#updating-items)

In order to update an item simply fetch it via `$cart->get` and then adjust the properties as needed.

```
try {
    $item = $cart->get($rowId);
    $item->setPrice(15);

    $cart->save();
} catch(ItemNotFoundException $e) {
    // handle appropriately
}
```

### Deleting

[](#deleting)

Deleting items is as easy as calling `$cart->delete` with the appropriate rowId.

### Clearing the whole cart

[](#clearing-the-whole-cart)

The method `$cart->clear` deletes all items on the cart.

### Summary

[](#summary)

Cart summary is available via the `getSummary` method which provides method like `getGrossPrice`, `getVat`, and `getNetPrice`.

CartItem
--------

[](#cartitem)

This is the class that represents an item in the cart. It's constructor accepts different parameters concerning the behaviour of an item.

Below is an example item creation:

```
$item = new CartItem(
    $pricePerUnit = 10,
    $quantity = 2,
    $vatRate = 20,
    // denotes whether the vat is included in the pricePerUnit supplied
    $vatIncluded = true
);
```

### Price information

[](#price-information)

After creating a `CartItem` instance, all the price details are available via the `getPriceInfo` method which returns the following details: `netPrice`, `netPricePerUnit`, `vat`, `vatPerUnit`, `grossPrice` and `grossPricePerUnit`.

Fees/Discounts
--------------

[](#feesdiscounts)

Discounts are supported via the `cartFees` property. It contains a collection of `CartFee`. These can be either flat values, percentages, discounts or as additional fees on the cart total.

```
// Flat discount
$cart->getCartFees()->add(new CartFee('15 EUR Discount', -15));

// Percent value
$cart->getCartFees()->add(new CartFee('2% Discount', '-2%'));
```

Processing and or other fees that increase the total of the cart should be added as cart items to better handle the different VAT rates each individual fee may have.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance57

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

280d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

invoicecartshopping

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[horstoeko/zugferd

A library for creating and reading european electronic invoices

4044.3M18](/packages/horstoeko-zugferd)[num-num/ubl-invoice

A modern object-oriented PHP library to create and read valid UBL and EN 16931/Peppol BIS 3.0 files

135820.5k](/packages/num-num-ubl-invoice)[amsgames/laravel-shop

Package set to provide shop or e-commerce functionality (such as CART, ORDERS, TRANSACTIONS and ITEMS) to Laravel for customizable builds.

4845.9k](/packages/amsgames-laravel-shop)[contributte/invoice

Library for easily and quickly creating invoices for customers.

97729.9k](/packages/contributte-invoice)[payum/offline

The Payum extension. It provides Offline payment integration.

323.4M13](/packages/payum-offline)

PHPackages © 2026

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