This package lets you define Coupons that can be applied to User Cart before placing an Order, calculating a discount depending on multiple different, configurable rules.
composer require escolalms/vouchers
php artisan migrate
php artisan db:seed --class="EscolaLms\Vouchers\Database\Seeders\VoucherPermissionsSeeder"
This package depends (and extends) on EscolaLms/Cart package and can not be used separately.
Every coupon defines set of rules that are checked when User tries to add Coupon to Cart. Only if all conditions are met, coupon (discount) can be applied to given Cart content. Some of the conditions work differently depending on type of coupon.
- Min/max amount - cart value must be at least "min" amount, and if cart value is above "max" amount, discount is only calculated as if value was at the "max" level
- Usage limits - coupons can not be used after their global or per user limits are reached
- Exclude promotions - coupon can not be used if products with already discounted price are in the Cart
This package defines four type of discounts, that represent four separate strategies for calculating discount. There are two types that relate to whole Cart and two types that relate to specified Products.
Coupon of type EscolaLms\Vouchers\Enums::CART_FIXED
substracts constant amount from total price of Cart. See EscolaLms\Vouchers\Strategies\CartFixedDiscountStrategy
.
- At least one of "included products" must be in Cart
- None of "excluded products" must be in Cart
- At least one of "included categories" must be in Cart
- None of "exclude categories" must be in Cart
Coupon of type EscolaLms\Vouchers\Enums::CART_PERCENT
substracts percentage based amount from total price of Cart, but only for Products not in "excluded products" or "excluded categories" list. See EscolaLms\Vouchers\Strategies\CartPercentDiscountStrategy
.
- At least one of "included products" must be in Cart
- At least one of "included categories" must be in Cart
Coupon of type EscolaLms\Vouchers\Enums::PRODUCT_FIXED
substracts constant amount from Product price, but only once per unique Product. Product must be specified in "included products". See EscolaLms\Vouchers\Strategies\ProductFixedDiscountStrategy
.
Coupon of type EscolaLms\Vouchers\Enums::PRODUCT_FIXED
substracts percentage based amount from Product price. Product must be specified in "included products". See EscolaLms\Vouchers\Strategies\ProductPercentDiscountStrategy
.
Coupon can be added to Cart using POST /api/cart/voucher/
endpoint.
All the endpoints are defined in .
Run ./vendor/bin/phpunit
to run tests. See tests directory.
There are no events emitted by this package.
There are no listeners specified in this package.
Permissions are defined in Enum and seeded in Seeder.
- endpoint for removing Coupon from Cart