Download the PHP package armezit/lunarphp-purchase-limit without Composer
On this page you can find all versions of the php package armezit/lunarphp-purchase-limit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download armezit/lunarphp-purchase-limit
More information about armezit/lunarphp-purchase-limit
Files in armezit/lunarphp-purchase-limit
Package lunarphp-purchase-limit
Short Description Lunar E-Commerce Purchase Limit Addon
License MIT
Homepage https://github.com/armezit/lunarphp-purchase-limit
Informations about the package lunarphp-purchase-limit
Lunar Purchase Limit Addon
The Purchase Limit addon for Lunar allows you to define complex purchase limitation scenarios in your Lunar store.
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.
Quick Setup
Install the Lunar Purchase Limit via composer:
Run the migrations with:
Usage
By default, after quick setup, you can start to define purchase limits on products and customers. There is also a detailed installation guide, in case you need more customization.
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:
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
:
Any
customer is allowed to purchase at most10
units of the product in eachWeek
.- Customers of
Retail
group are allowed to purchase at most2000
total sum of the product inEach Purchase
. So, for example, if price of product is $500, they can only purchase up to 4 unit of productA
in each order.
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)
The Customer Purchase Limit slot will let you define limitations for a specific customer or customer group.
TODO: Not Yet Implemented !
Advanced Usage
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
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 Model.
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:
or
Installation
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:
Migrations
Optionally, publish the migrations:
Run the migrations with:
::: tip Table names are configurable. See the config file. :::
Config
You can publish the config file with:
This is the contents of the published config file:
Translations & Views
Optionally, you can publish the translations and views using
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.
The PurchaseLimitServiceProvider
bootstrap primary package features,
while the PurchaseLimitHubServiceProvider
is used to register some
Slots to be used in Lunar Admin Hub.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Armin Rezayati
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of lunarphp-purchase-limit with dependencies
livewire/livewire Version ^2.0
spatie/laravel-package-tools Version ^1.9.2
lunarphp/lunar Version ^0.8