autepos/discount
Composer 安装命令:
composer require autepos/discount
包简介
Flexible discount interface
关键字:
README 文档
README
A flexible discounting library for PHP with zero dependency. It is typically used to provide discounts on products, but can be used for any kind of discounting where flexibility is required.
Features
- Zero dependency
- Flexible discounting
- Extensible
- Supports multiple discount types:
- Percentage
- Fixed amount
- BOGO / Buy N get M free / Buy N for the Price of M
- Buy N at a price
- Discount stacking: any type/multiple discounts can be applied to a single/multiple items. Zero limitation.
- Restricting discounts:
- to specific items
- to a minimum purchase amount
- to minimum quantity
- etc.
Installation
Install the latest version with
composer require autepos/discount
Basic Usage
use Autepos\Discount\Processors\LinearDiscountProcessor; use Autepos\Discount\Contracts\DiscountableDevice; use Autepos\Discount\Contracts\DiscountInstrument; class Order implements DiscountableDevice { //... } class PromotionCode implements DiscountInstrument { //... } $discountableDevice = new Order(); $discountInstrument = new PromotionCode(); $processor = new LinearDiscountProcessor(); $processor->addDiscountableDevice($discountableDevice) ->addDiscountInstrument($discountInstrument); $discountLineList = $processor->calculate(); // Get the discount amount $discountAmount = $discountLineList->amount(); // Persist the discount $discountLineList->redeem();
Adding a custom discount processor
use Autepos\Discount\Processors\Contracts\DiscountProcessor; class CustomDiscountProcessor implements DiscountProcessor { public function getProcessor(): string { return 'custom'; } //... }
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-07