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

ActiveLibrary[Payment Processing](/categories/payments)

gabrieljmj/cart
===============

Simple shopping cart system

618PHP

Since Jan 1Pushed 11y ago2 watchersCompare

[ Source](https://github.com/GabrielJMJ/Cart)[ Packagist](https://packagist.org/packages/gabrieljmj/cart)[ RSS](/packages/gabrieljmj-cart/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Gabrieljmj\\Cart
================

[](#gabrieljmjcart)

[![Total Downloads](https://camo.githubusercontent.com/d77fa501a813bb4d59eeef130770794882ecbed5332207012c75e806a47b09a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6761627269656c6a6d6a2f636172742e7376673f7374796c653d666c6174)](https://packagist.org/packages/gabrieljmj/cart) [![Latest Unstable Version](https://camo.githubusercontent.com/8ecc0126125d40071866cd3da9dbc2d6ad9172530e852f2d3d05b6a6ae17e873/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6465762d2d6d61737465722d6f72616e67652e7376673f7374796c653d666c6174)](https://packagist.org/packages/gabrieljmj/cart) [![License](https://camo.githubusercontent.com/e2d85994f4a41eb50dabd492c54a6583b6f63b9d01e6d9ddfbcdaedd4e5dd955/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d6c69676874677265792e7376673f7374796c653d666c6174)](https://packagist.org/packages/gabrieljmj/cart) [![Build Status](https://camo.githubusercontent.com/c5ea32325ddd4db2ee280088b85526b7f00bc66e94b7b86a6ea0bc343411dec1/68747470733a2f2f7472617669732d63692e6f72672f4761627269656c4a4d4a2f436172742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/GabrielJMJ/Cart) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/0a852ce7189ad156cd6c33862153e7acd34468fcd0c1d1532009471e7ac7ef3a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6761627269656c6a6d6a2f636172742e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/GabrielJMJ/Cart/?branch=master)

Simple shopping cart system.

\##Usage ####Adding product to cart Use the method `\Gabrieljmj\Cart\Cart::add(ProductInterface $product)` to add a product. If previously the same product was added, will be add one more to cart.

```
use Gabrieljmj\Cart\Product\Product;
use Gabrieljmj\Cart\Cart;

$product = new Product(1, 'TV', 499.90, ['tv', 'led']);
$cart = new Cart();
$cart->add($product);
```

\####Removing product of a cart Using `\Gabrieljmj\Cart\Cart::remove($product[, $amount = 0])` you can remove products of a cart. If `$amount` be `0`, all products of that products will be removed. The argument `$product` can be an instance of `\Gabrieljmj\Cart\Product\ProductInterface` or product id.

```
$cart->remove(1);
```

\####Clearing the cart To this use the method `\Gabrieljmj\Cart\Cart::clear`.

```
$cart->clear();
```

\####Verifying if the cart has a product The `$product` argument can be the product id or an instance of `\Gabrieljmj\Cart\Product\ProductInterface`. The return will be boolean.

```
$cart->has($product);
```

\####Counting how many products has in the cart The method `\Gabrieljmj\Cart\Cart::count()` will return how many items has in the cart.

```
$cart->count();
```

\####Counting how many products of a type has in the cart Use the method `\Gabrieljmj\Cart\Cart::getTotalOfAProduct($product)` and like others, `$product` can be an instance of `\Gabrieljmj\Cart\Product\ProductInterface` or product id.

```
$cart->getTotalOfAProduct($product);
```

\####Counting how many types of products has in the cart And this method (`\Gabrieljmj\Cart\Cart::countUniqueItems()`) counts how many types of products has in the cart.

```
$cart->countUniqueItems();
```

\####Calculating total price of the cart The method `\Gabrieljmj\Cart\Cart::getTotalPrice()` returns how much costs the cart.

```
$cart->getTotalPrice();
```

\####Iterating with all products Each product will return an instance of `\Gabrieljmj\Cart\Product\ProductInterface`:

```
$iterator = $cart->getIterator();

while ($iterator->valid()) {
    $curr = $iterator->current();
    echo 'Product:' . $curr->getProduct()->getName() . ' / Total: ' . $cart->getTotalOfAProduct($curr) . '';
    $iterator->next();
}
```

\####Storaging The instance of the cart usually is save on a session or a cookie.

```
$_SESSION['cart'] = $cart;
//or
setcookie('cart', $cart);
```

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4fcbdf815749595d3dcfd4fb781e2cac05aa6d132123aa9da889d2c5ca6c8e11?d=identicon)[GabrielJMJ](/maintainers/GabrielJMJ)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

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