PHPackages                             armezit/lunarphp-purchase-limit - 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. armezit/lunarphp-purchase-limit

ActiveLibrary

armezit/lunarphp-purchase-limit
===============================

Lunar E-Commerce Purchase Limit Addon

v0.8.3(2y ago)72012[2 PRs](https://github.com/armezit/lunarphp-purchase-limit/pulls)MITPHPPHP ^8.0

Since Aug 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/armezit/lunarphp-purchase-limit)[ Packagist](https://packagist.org/packages/armezit/lunarphp-purchase-limit)[ Docs](https://github.com/armezit/lunarphp-purchase-limit)[ Fund](https://commerce.coinbase.com/checkout/8f4a04e6-a8e6-4bb6-aa8b-4c8037944b20)[ RSS](/packages/armezit-lunarphp-purchase-limit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (13)Versions (16)Used By (0)

Lunar Purchase Limit Addon
==========================

[](#lunar-purchase-limit-addon)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d71fb5d597d7399f6bfec69317a23f0e6290c033f70e30f18ae6396834a2ffba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61726d657a69742f6c756e61727068702d70757263686173652d6c696d69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/armezit/lunarphp-purchase-limit)[![GitHub Tests Action Status](https://camo.githubusercontent.com/16aa9c33a7165b3a17b8273ba39f13b992d218113737a3233a1a137e363b20b2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61726d657a69742f6c756e61727068702d70757263686173652d6c696d69742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/armezit/lunarphp-purchase-limit/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/9a8932642f46b3706c4cd72c61d38d46e5d0b1ff0df1330ae5bc7a79f784fe83/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61726d657a69742f6c756e61727068702d70757263686173652d6c696d69742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65)](https://github.com/armezit/lunarphp-purchase-limit/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/10acc2d299915376380bfb64c031f2787ceeee34f9c03d3933cff6e9e2bf79d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61726d657a69742f6c756e61727068702d70757263686173652d6c696d69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/armezit/lunarphp-purchase-limit)

The Purchase Limit addon for Lunar allows you to define complex purchase limitation scenarios in your [Lunar](https://github.com/lunarphp/lunar) store.

Features
--------

[](#features)

You can define a criteria for each rule. Currently, you are able to define purchase limits for:

- a specific Product
- a specific Product Variant
- a Customer or Customer Group
- a specific Product for a specific Customer or Customer Group
- a specific Product Variant for a specific Customer or Customer Group

Each purchase limit rule allows you to restrict either quantity, amount (total sum), or both of them.

[![Product Purchase Limit Slot](docs/assets/product-purchase-limit-screenshot.png?raw=true "Product Purchase Limit")](docs/assets/product-purchase-limit-screenshot.png?raw=true)

Quick Setup
-----------

[](#quick-setup)

Install the Lunar Purchase Limit via composer:

```
composer require armezit/lunarphp-purchase-limit
```

Run the migrations with:

```
php artisan migrate
```

Usage
-----

[](#usage)

By default, after quick setup, you can start to define purchase limits on products and customers. There is also a detailed [installation guide](#installation), in case you need more customization.

### Detect Violation of Defined Limitations

[](#detect-violation-of-defined-limitations)

The package throws a child type of `Lunar\Exceptions\Carts\CartException` exception, each time a violation of defined limits detected.

Typically, you want to catch these exceptions during create order process:

```
use Lunar\Facades\CartSession;
use Lunar\Exceptions\Carts\CartException;
use Armezit\Lunar\PurchaseLimit\Exceptions\PurchaseLimitException;
use Armezit\Lunar\PurchaseLimit\Exceptions\CustomerQuantityLimitException;

try {
    $order = CartSession::current()
                ->getManager()
                ->createOrder();

// catch any CartException
} catch (CartException $e) {
    ...

// catch any kind of purchase limit violation
} catch (PurchaseLimitException $e) {
    ...

// catch specific kind of purchase limit violation
} catch (CustomerQuantityLimitException $e) {
    // customer quantity limit exceeded
}
```

### Product Purchase Limit (Slot)

[](#product-purchase-limit-slot)

The **Product Purchase Limit** slot will let you define limitations for a specific product.

In the following example, we have defined limitation rules for product `A`:

1. `Any` customer is allowed to purchase at most `10` units of the product in each `Week`.
2. Customers of `Retail` group are allowed to purchase at most `2000` total sum of the product in `Each Purchase`. So, for example, if price of product is $500, they can only purchase up to 4 unit of product `A` in each order.

[![Product Purchase Limit Example 1](docs/assets/product-purchase-limit-example-01.png?raw=true "Product Purchase Limit Example 1")](docs/assets/product-purchase-limit-example-01.png?raw=true)

BY default, you will find this slot in bottom of the product edit page. However, you can change this default position in config file.

### Customer Purchase Limit (Slot)

[](#customer-purchase-limit-slot)

The **Customer Purchase Limit** slot will let you define limitations for a specific customer or customer group.

*TODO: Not Yet Implemented !*

Advanced Usage
--------------

[](#advanced-usage)

### Architecture

[](#architecture)

The primary component is `Rule` classes, which check defined limitations (stored in database) and throw exception if a violation of rule detected.

There are two kinds of rules which implement either `CartRuleInterface` or `CartLineRuleInterface` contracts.

Each rule perform only a unique type of checks.

For example, `CustomerProductLimit` rule only checks purchase limits of a specific customer on a specific product.

While `CustomerLimit` rule only checks purchase limits of a specific customer on any product, and `ProductLimit` rules only checks purchase limits of any customer on a specific product; And so on.

These rules are injected into the Cart/CartLine modifiers pipelines.

So, everytime you try to call `CreateOrder` action, these rules execute one by one and throw exception if detect violation of defined limitations.

### Complex Rules

[](#complex-rules)

Although there is Hub slots for defining typical limitations, nothing prevents you to compose more complex rules by saving purchase limits directly in database.

Take a look at the [PurchaseLimit](src/Models/PurchaseLimit.php) Model.

### Extend

[](#extend)

In addition, you can extend/modify business logic by implementing `CartRuleInterface` and/or `CartLineRuleInterface`contracts and inject them into the modifier pipelines.

After implementing a new `CheckVeryComplexLimit` rule, add it to the corresponding pipeline in config file:

```
'cart_rules' => [
    ...
    CheckVeryComplexLimit::class,
],
```

or

```
'cart_line_rules' => [
    ...
    CheckVeryComplexLimit::class,
],
```

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

[](#installation)

[Quick Setup](#quick-setup) covers the essential installation steps. This section, however, is a detailed installation procedure, containing all optional parts.

You can install the package via composer:

```
composer require armezit/lunarphp-purchase-limit
```

### Migrations

[](#migrations)

Optionally, publish the migrations:

```
php artisan vendor:publish --tag="lunarphp-purchase-limit-migrations"
```

Run the migrations with:

```
php artisan migrate
```

::: tip Table names are configurable. See the config file. :::

### Config

[](#config)

You can publish the config file with:

```
php artisan vendor:publish --tag="lunarphp-purchase-limit-config"
```

This is the contents of the published config file:

```
return [
    /*
     * List of rules to check during CartModifier::calculated() hook
     */
    'cart_rules' => [
        ProductLimit::class,
        CustomerLimit::class,
        CustomerProductLimit::class,
    ],

    /*
     * List of rules to check during CartLineModifier::calculated() hook
     */
    'cart_line_rules' => [
        ProductVariantLimit::class,
        CustomerProductVariantLimit::class,
    ],

    /*
     * Automatically register purchase-limit`s cart/cart-line modifiers during PurchaseLimitServiceProvider boot
     * Set it to false, if you want to manually register cart/cart-line modifiers
     */
    'register_cart_modifiers' => true,

    /*
     * Automatically register purchase-limit admin hub slots
     * Set it to false, if you want to manually register them
     */
    'register_hub_slots' => true,

    /*
     * The name (handle) of hub slot which you want to display product purchase limit component
     */
    'product_purchase_limit_slot' => 'product.all',

    'database' => [
        'purchase_limits_table' => 'purchase_limits',
    ],
];
```

### Translations &amp; Views

[](#translations--views)

Optionally, you can publish the translations and views using

```
php artisan vendor:publish --tag="lunarphp-purchase-limit-translations"
php artisan vendor:publish --tag="lunarphp-purchase-limit-views"
```

### Service provider

[](#service-provider)

By default, this package automatically register it`s service providers when it is installed.

If for any reason you prefer to register them manually, you should add the package service providers into your laravel application's `config/app.php` file.

```
// ...
'providers' => [
    // ...
    Armezit\Lunar\PurchaseLimit\PurchaseLimitServiceProvider::class,
    Armezit\Lunar\PurchaseLimit\PurchaseLimitHubServiceProvider::class,
],
```

The `PurchaseLimitServiceProvider` bootstrap primary package features, while the `PurchaseLimitHubServiceProvider` is used to register some [Slots](https://docs.lunarphp.io/extending/admin-hub.html#slots) to be used in Lunar Admin Hub.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/armezit/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Armin Rezayati](https://github.com/armezit)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.6% 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 ~50 days

Recently: every ~67 days

Total

12

Last Release

807d ago

### Community

Maintainers

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

---

Top Contributors

[![armezit](https://avatars.githubusercontent.com/u/2006991?v=4)](https://github.com/armezit "armezit (55 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")

---

Tags

laravelecommercee-commercelunarpurchase-limit

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/armezit-lunarphp-purchase-limit/health.svg)

```
[![Health](https://phpackages.com/badges/armezit-lunarphp-purchase-limit/health.svg)](https://phpackages.com/packages/armezit-lunarphp-purchase-limit)
```

###  Alternatives

[jsdecena/laracom

Laravel powered e-commerce

2.0k4.4k](/packages/jsdecena-laracom)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[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)[lunarphp/stripe

Stripe payment driver for Lunar.

2055.8k4](/packages/lunarphp-stripe)[getcandy/core

GetCandy Laravel e-commerce core functionality.

156.6k3](/packages/getcandy-core)[a2insights/filament-saas

Filament Saas for A2Insights

161.1k](/packages/a2insights-filament-saas)

PHPackages © 2026

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