Download the PHP package mohammadmehrabani/conditional-coupon without Composer
On this page you can find all versions of the php package mohammadmehrabani/conditional-coupon. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mohammadmehrabani/conditional-coupon
More information about mohammadmehrabani/conditional-coupon
Files in mohammadmehrabani/conditional-coupon
Package conditional-coupon
Short Description The conditional coupon for the Laravel.
License MIT
Homepage https://github.com/mohammadmehrabani/conditional-coupon
Informations about the package conditional-coupon
conditional coupon code
With this package, you can add both simple and conditional discount coupon features to your application. You can develop your own custom conditions, which will be automatically checked when a discount coupon is applied. If a condition is violated, an error will be returned and the coupon will not be allowed to be used by the user.
Installation
You can install the package via composer:
You can publish and run the migrations with:
You can publish the config file with:
This is the contents of the published config file:
If you want any conditions to be checked when applying a discount coupon, simply create a class that implements \MohammadMehrabani\ConditionalCoupon\CheckConditionAbstract and add it to the conditional-coupon.php config file along with a title for the condition. No further action is needed—it's that simple.
add to config file:
Usage
Implementing the CRUD for discount coupons—and adding conditions if needed—is up to you. Once created, you can simply use the discount coupon feature for your orders as shown in the example below.
Listing Available Check Classes
You can retrieve all available Check classes using the GetCustomConditions class.
Each Check class has a title property which is wrapped in __() for translation.
This list can be used to populate the select box when creating discount coupons.
create coupon with conditions
create coupon without conditions
use coupon for order
Discount Logic
The package supports two types of discount fields:
discount_percentagediscount_amount
Rules
-
Single Field Case
- If only one of the fields is provided, the discount will be applied based on that field.
- Both Fields Case
- If both
discount_percentageanddiscount_amountare provided:- The discount value is first calculated from the
discount_percentage. - If the calculated percentage discount is greater than the fixed
discount_amount, then the fixed amount will be applied. - If the calculated percentage discount is less than or equal to the fixed
discount_amount, then the percentage-based discount will be applied.
- The discount value is first calculated from the
- If both
Example
- Order total: $200
discount_percentage: 20%discount_amount: $30
Calculation:
- 20% of $200 = $40
- Since $40 (percentage) > $30 (amount), the final discount will be $30.
Testing
Contributing
Please see CONTRIBUTING for details.
Credits
- Mohammad Hossein Mehrabani
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of conditional-coupon with dependencies
illuminate/support Version ^9.0||^10.0||^11.0||^12.0
illuminate/filesystem Version ^9.0||^10.0||^11.0||^12.0
illuminate/contracts Version ^9.0||^10.0||^11.0||^12.0
illuminate/database Version ^9.0||^10.0||^11.0||^12.0