PHP code example of adeela / user-discounts
1. Go to this page and download the library: Download adeela/user-discounts library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adeela / user-discounts example snippets
'providers' => [
Adeela\UserDiscounts\UserDiscountsServiceProvider::class,
],
return [
'stacking_order' => 'highest_first',
'max_percentage_cap' => 50,
'rounding' => 'round',
];
use Adeela\UserDiscounts\Models\Discount;
$discount = Discount::create([
'code' => 'Save20',
'name' => 'Save 20%',
'type' => 'percentage',
'value' => 20,
'active' => 1,
'starts_at' => now()->subDay(),
'ends_at' => now()->addDay(),
]);
$service = new \Adeela\UserDiscounts\Services\DiscountService();
$user = User::find(1);
$discount = Discount::find(34);
$service->assign($user, $discount);
$service = new \Adeela\UserDiscounts\Services\DiscountService();
$amount = 100;
$orderRef = 'ORDER-12345';
$user = User::find(1);
$finalAmount = $service->apply($user, $amount, $orderRef);
dd("Final amount after discounts: {$finalAmount}");
$service = new \Adeela\UserDiscounts\Services\DiscountService();
$user = User::find(1);
$discount = Discount::find(34);
$service->revoke($user, $discount);
bash
php artisan vendor:publish --provider="Adeela\UserDiscounts\UserDiscountsServiceProvider" --tag="config"
bash
php artisan migrate