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

ActiveLibrary[Payment Processing](/categories/payments)

pinga/cart
==========

A simple PHP shopping cart package

v0.5.1(3y ago)181MITPHPPHP &gt;=8.1.0

Since Mar 9Pushed 3y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Pinga Cart
==========

[](#pinga-cart)

This is a very simple PHP cart library. Cart data can either be saved in PHP session or browser cookie. Maintained and expanded by Taras Kondratyuk and based on seikan/Cart.

Usage
-----

[](#usage)

### Configuration

[](#configuration)

1. Install the package:

```
composer require pinga/cart

```

2. Include in your main PHP script:

```
require_once '../vendor/autoload.php';
```

3. Use in your script:

```
use Pinga\Cart\Cart;
$cart= new Cart( [array $options] );
```

##### Options

[](#options)

ParameterTypeDescriptioncartMaxItem**int**The maximum item can be added to cart. 0 = UnlimiteditemMaxQuantity**int**The maximum quantity per item can be added to cart. 0 = UnlimiteduseCookie**bool**Use cookie to keep cart data when browser is closed.```
// Include core Cart library
require_once 'class.Cart.php';

// Initialize Cart object
$cart = new Cart([
  // Can add unlimited number of item to cart
  'cartMaxItem'      => 0,

  // Set maximum quantity allowed per item to 99
  'itemMaxQuantity'  => 99,

  // Do not use cookie, cart data will lost when browser is closed
  'useCookie'        => false,
]);
```

### Add Item

[](#add-item)

Adds an item to cart.

> **bool** $cart-&gt;add( **string** $id\[, **int** $quantity\]\[, **array** $attributes\] );

```
// Add item with ID #1001
$cart->add('1001');

// Add 5 item with ID #1002
$cart->add('1002', 5);

// Add item with ID #1003 with price, color, and size
$cart->add('1003', 1, [
  'price'  => '5.99',
  'color'  => 'White',
  'size'   => 'XS',
]);

// Item with same ID but different attributes will added as separate item in cart
$cart->add('1003', 1, [
  'price'  => '5.99',
  'color'  => 'Red',
  'size'   => 'M',
]);
```

### Update Item

[](#update-item)

Updates quantity of an item. Attributes **must be** provides if item with same ID exists with different attributes.

> **bool** $cart-&gt;update( **string** $id, **int** $quantity\[, **array** $attributes\] );

```
// Set quantity for item #1001 to 5
$cart->update('1001', 5);

// Set quantity for item #1003 to 2
$cart->update('1003', 2, [
  'price'  => '5.99',
  'color'  => 'Red',
  'size'   => 'M',
]);
```

### Remove Item

[](#remove-item)

Removes an item. Attributes **must be** provided to remove specified item, or all items with same ID will be removed from cart.

> **bool** $cart-&gt;remove( **string** $id\[, **array** $attributes\] );

```
// Remove item #1001
$cart->remove('1001');

// Remove item #1003 with color White and size XS
$cart->remove('1003', [
  'price'  => '5.99',
  'color'  => 'White',
  'size'   => 'XS',
]);
```

### Get Items

[](#get-items)

Gets a multi-dimensional array of items stored in cart.

> **array** $cart-&gt;getItems( );

```
// Get all items in the cart
$allItems = $cart->getItems();

foreach ($allItems as $items) {
  foreach ($items as $item) {
    echo 'ID: '.$item['id'].'';
    echo 'Qty: '.$item['quantity'].'';
    echo 'Price: '.$item['attributes']['price'].'';
    echo 'Size: '.$item['attributes']['size'].'';
    echo 'Color: '.$item['attributes']['color'].'';
  }
}
```

### Get Item

[](#get-item)

Gets a multi-dimensional array of one item stored in cart.

> **array** $cart-&gt;getItem( **string** $id\[, **string** $hash\] );

```
// Get first one item from the cart with id 1001
$theItem = $cart->getItem('1001');

// Get one item from the cart with any id and hash
$theItem = $cart->getItem($item['id'], $item['hash']);
```

### Check Cart Empty

[](#check-cart-empty)

Checks if the cart is empty.

> **bool** $cart-&gt;isEmpty( );

```
if ($cart->isEmpty()) {
  echo 'There is nothing in the basket.';
}
```

### Get Total Item

[](#get-total-item)

Gets the total of items in the cart.

> **int** $cart-&gt;getTotaltem( );

```
echo 'There are '.$cart->getTotalItem().' items in the cart.';
```

### Get Total Quantity

[](#get-total-quantity)

Gets the total of quantity in the cart.

> **int** $cart-&gt;getTotalQuantity( );

```
echo $cart->getTotalQuantity();
```

### Get Attribute Total

[](#get-attribute-total)

Gets the sum of a specific attribute.

> **int** $cart-&gt;getAttributeTotal( **string** $attribute );

```
echo 'Total Price: $'.number_format($cart->getAttributeTotal('price'), 2, '.', ',').'';
```

### Clear Cart

[](#clear-cart)

Clears all items in the cart.

> $cart-&gt;clear( );

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

### Destroy Cart

[](#destroy-cart)

Destroys the entire cart session.

> $cart-&gt;destroy( );

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

### Item Exists

[](#item-exists)

Checks if an item exists in cart.

> **bool** $cart-&gt;isItemExists( **string** $id\[, **array** $attributes\] );

```
if ($cart->isItemExists('1001')) {
  echo 'This item already added to cart.';
}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

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

Total

2

Last Release

1166d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

Simplecartshopping

### Embed Badge

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

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

###  Alternatives

[amsgames/laravel-shop

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

4775.9k](/packages/amsgames-laravel-shop)[lunarphp/stripe

Stripe payment driver for Lunar.

2055.8k4](/packages/lunarphp-stripe)[sunnysideup/ecommerce

Silverstripe E-commerce Application

257.2k79](/packages/sunnysideup-ecommerce)

PHPackages © 2026

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