PHPackages                             unisharp/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. [Caching](/categories/caching)
4. /
5. unisharp/cart

ActiveLibrary[Caching](/categories/caching)

unisharp/cart
=============

let buyable item can add to cart

11.7kPHP

Since Sep 26Pushed 7y ago10 watchersCompare

[ Source](https://github.com/UniSharp/cart)[ Packagist](https://packagist.org/packages/unisharp/cart)[ RSS](/packages/unisharp-cart/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

UniSharp Cart
=============

[](#unisharp-cart)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8254c8871958bed8b1f01907e2ae96fd46e4b0159494b669d45c959afd440b14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f556e6953686172702f636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/unisharp/cart)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/52155c9db5d6603faac5f7f72bdb7db0a0dda8dde00b75a45f5a68f9a93ab08f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f556e6953686172702f636172742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/UniSharp/cart)[![Coverage Status](https://camo.githubusercontent.com/2cc3f321c098dfe8df4673c06cb13d1bd78f7e219c33c49665e039134402d931/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f556e6953686172702f636172742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/UniSharp/cart/code-structure)[![Quality Score](https://camo.githubusercontent.com/469c2da897096b984dd1440dc7e77b65741c1c1ea3599335c8172e8f3e3bb09a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f556e6953686172702f636172742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/UniSharp/cart)[![Total Downloads](https://camo.githubusercontent.com/0b40a18a26600c1c58b39321e43ff1827448b4e852025826c98bf395492e9498/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f556e6953686172702f636172742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/UniSharp/cart)

Let buyable item can add to cart, and make order with cart's items, and also provide payment feature.

This package depends on:

- [unisharp/buyable](https://github.com/UniSharp/buyable)
- [unisharp/pricing](https://github.com/UniSharp/pricing)
- [voicetube/taiwan-payment-gateway](https://github.com/voicetube/Taiwan-Payment-Gateway)
- [unisharp/payment](https://github.com/UniSharp/unisharp-payment)

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

[](#installation)

`composer require unisharp/cart dev-master`

Cart Usages
-----------

[](#cart-usages)

### Use Api

[](#use-api)

Include api into `api.php`

```
Route::group(['prefix' => 'v1'], function () {
    CartManager::route();
});
```

route lists:

MethodUriCommentPOSTapi/v1/cartsCreate the cartDELETEapi/v1/carts/{cart}Delete the cart and cart's itemsGETapi/v1/carts/{cart}Get the cart and cart's itemsPUTapi/v1/carts/{cart}Add item(s) to the cartPOSTapi/v1/carts/{cart}Refresh cart and add item(s) to the cartDELETEapi/v1/carts/{cart}/{item}Remove a item from the cart### Use CartManager

[](#use-cartmanager)

Create a new cart

```
$cart = CartManager::make();
```

Get a exist cart

```
$cart = CartManager::make($cart);
```

Add item to the cart

```
$item = new Item([
    'id' => 1,
    '$quantity' => 10,
    'extra' => [
        'comment' => '...'
    ]
]);

$cart->add($item->id, $item->quantity, $item->extra)->save();
```

Get cart's items

```
$cart->getCartInstance()->getItems();
```

Remove item from the cart

```
$cart->remove($item)->save();
```

Clean cart's items

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

Destroy the cart

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

Order Usages
------------

[](#order-usages)

### Use Api

[](#use-api-1)

Include api into `api.php`

```
Route::group(['prefix' => 'v1'], function () {
    OrderManager::route();
});
```

route lists:

MethodUriCommentPOSTapi/v1/ordersCreate an orderGETapi/v1/ordersList all ordersDELETEapi/v1/orders/{order}Delete the orderPUTapi/v1/orders/{order}Update the order's status, price and shipping\_statusGETapi/v1/orders/{order}Get the orderDELETEapi/v1/orders/{order}/{item}Remove a item from the orderGETapi/v1/user/me/order-itemsGet current user's orders### Use OrderManager

[](#use-ordermanager)

Create an order manager

```
// Get order manager
$order = OrderManager::make();

// Assign operator
$order->assign(auth()->user());

// Checkout cart's items and buyer and receiver's information
$items = CartManager::make($cart)->getItems();
$information = [
    'buyer' => [],
    'receiver' => [],
    'payment' => 'credit'
];
$order->checkout(items, informations)
```

Get an exist order

```
$order = OrderManager::make($order)->getOrderInstance();
```

Pricing Usages
==============

[](#pricing-usages)

Both of CartManager and OrderManager already have trait

```
class CartManager
{
    use CanPricing;
    ...
}
```

Customize pricing module

```
use UniSharp\Pricing\Pricing;
use UniSharp\Pricing\ModuleContract;

class CustomPricingModule implements ModuleContract
{
    public function handle(Pricing $pricing, Closure $next)
    {
        ...
        return $next($pricing);
    }

    public function finish(Pricing $pricing)
    {
        ...
    }
}
```

Set Custom pricing module in `config/pricing.php`

```
return [
    'modules' => [
        CustomPricingModule::class
    ],
];
```

Get pricing

```
// get original price
$cart->getOriginalPrice();

// get total price
$cart->getPrice();

// get fee
$cart->getFee();
```

More details on [unisharp/pricing](https://github.com/UniSharp/pricing)

Payment Usages
--------------

[](#payment-usages)

Set payment gateway config

```
return [
    'payment' => [
        'driver'         => 'EcPay',
        'merchantId'     => '2000132',
        'hashKey'        => '5294y06JbISpM5x9',
        'hashIV'         => 'v77hoKGq4kWxNNIS',
        'actionUrl'      => 'https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/',
        'returnUrl'      => 'https://localhost/payment/confirm',
        'notifyUrl'      => 'https://localhost/payment/notify',
        'clientBackUrl'  => 'https://localhost/payment/return',
        'paymentInfoUrl' => 'https://localhost/payment/information'
    ],
]
```

Set api into `api.php`

```
// Include payment api
Route::group(['prefix' => 'v1'], function () {
    OrderManager::route();
});

// Implement payment response url
Route::group(['prefix' => 'v1/payment'], function () {
    Route::get('confirm', function () {...});
    Route::get('notify', function () {...});
    Route::get('return', function () {...});
    Route::get('information', function () {...});
});
```

MethodUriCommentGETapi/v1/orders/{order}/payCall paymentGETapi/v1/payment/confirmPayment completed urlGETapi/v1/payment/notifyNotify urlGETapi/v1/payment/returnClient back urlGETapi/v1/payment/informationPayment Information url

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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://avatars.githubusercontent.com/u/1203922?v=4)[FreedomKnight](/maintainers/FreedomKnight)[@FreedomKnight](https://github.com/FreedomKnight)

![](https://avatars.githubusercontent.com/u/181350?v=4)[Youchen Lee (isacl)](/maintainers/youchenlee)[@youchenlee](https://github.com/youchenlee)

---

Top Contributors

[![bluehaha2](https://avatars.githubusercontent.com/u/26923948?v=4)](https://github.com/bluehaha2 "bluehaha2 (12 commits)")[![CatheCat](https://avatars.githubusercontent.com/u/14325344?v=4)](https://github.com/CatheCat "CatheCat (10 commits)")[![streamtw](https://avatars.githubusercontent.com/u/7333171?v=4)](https://github.com/streamtw "streamtw (4 commits)")[![storyn26383](https://avatars.githubusercontent.com/u/6954098?v=4)](https://github.com/storyn26383 "storyn26383 (3 commits)")[![youchenlee](https://avatars.githubusercontent.com/u/181350?v=4)](https://github.com/youchenlee "youchenlee (3 commits)")

### Embed Badge

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

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

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)

PHPackages © 2026

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