Skip to content

Package: vouchers

Generated from api/packages/vouchers

Source: api/packages/vouchers · imported version 0.1.22. The sections after the README are extracted from the code on every docs build.

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 ulams/vouchers
  • php artisan migrate
  • php artisan db:seed --class="Ulams\Vouchers\Database\Seeders\VoucherPermissionsSeeder"

This package depends (and extends) on Ulams/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 Ulams\Vouchers\Enums::CART_FIXED substracts constant amount from total price of Cart. See Ulams\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 Ulams\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 Ulams\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 Ulams\Vouchers\Enums::PRODUCT_FIXED substracts constant amount from Product price, but only once per unique Product. Product must be specified in “included products”. See Ulams\Vouchers\Strategies\ProductFixedDiscountStrategy.

Coupon of type Ulams\Vouchers\Enums::PRODUCT_FIXED substracts percentage based amount from Product price. Product must be specified in “included products”. See Ulams\Vouchers\Strategies\ProductPercentDiscountStrategy.

Coupon can be added to Cart using POST /api/cart/voucher/ endpoint.

All the endpoints are defined in swagger.

Run ./vendor/bin/phpunit to run tests. See tests directory.

Test details codecov phpunit

There are no events emitted by this package.

There are no listeners specified in this package.

Menu

List of Coupons

Creating/editing Coupon

Permissions are defined in Enum and seeded in Seeder.

  • endpoint for removing Coupon from Cart
Method Path Auth Action
GET /api/admin/vouchers yes VouchersAdminApiController@index
POST /api/admin/vouchers yes VouchersAdminApiController@create
GET /api/admin/vouchers/{id} yes VouchersAdminApiController@read
PUT /api/admin/vouchers/{id} yes VouchersAdminApiController@update
PATCH /api/admin/vouchers/{id} yes VouchersAdminApiController@update
DELETE /api/admin/vouchers/{id} yes VouchersAdminApiController@delete
POST /api/cart/voucher VouchersApiController@apply
DELETE /api/cart/voucher VouchersApiController@unapply
Permission Seeded for roles Constant
coupon_list admin VoucherPermissionsEnum::COUPON_LIST
coupon_create admin VoucherPermissionsEnum::COUPON_CREATE
coupon_read admin VoucherPermissionsEnum::COUPON_READ
coupon_update admin VoucherPermissionsEnum::COUPON_UPDATE
coupon_delete admin VoucherPermissionsEnum::COUPON_DELETE
coupon_use admin, student, tutor VoucherPermissionsEnum::COUPON_USE

Registered with AdministrableConfig::registerConfig (editable in the admin panel under Configuration → Settings).

None.

None.

None.

None.

None.