|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of ibrand/discount. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) iBrand <https://www.ibrand.cc> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace iBrand\Component\Discount\Providers; |
|
13
|
|
|
|
|
14
|
|
|
use iBrand\Component\Discount\Actions\OrderFixedDiscountAction; |
|
15
|
|
|
use iBrand\Component\Discount\Actions\OrderPercentageDiscountAction; |
|
16
|
|
|
use iBrand\Component\Discount\Checkers\CartQuantityRuleChecker; |
|
17
|
|
|
use iBrand\Component\Discount\Checkers\ItemTotalRuleChecker; |
|
18
|
|
|
use iBrand\Component\Discount\Models\Coupon; |
|
19
|
|
|
use iBrand\Component\Discount\Policies\CouponPolicy; |
|
20
|
|
|
use iBrand\Component\Discount\Repositories\CouponRepository; |
|
21
|
|
|
use iBrand\Component\Discount\Repositories\DiscountRepository; |
|
22
|
|
|
use iBrand\Component\Discount\Repositories\Eloquent\CouponRepositoryEloquent; |
|
23
|
|
|
use iBrand\Component\Discount\Repositories\Eloquent\DiscountRepositoryEloquent; |
|
24
|
|
|
use Illuminate\Contracts\Auth\Access\Gate as GateContract; |
|
25
|
|
|
use Illuminate\Support\ServiceProvider; |
|
26
|
|
|
|
|
27
|
|
|
class DiscountServiceProvider extends ServiceProvider |
|
28
|
|
|
{ |
|
29
|
|
|
protected $policies = [ |
|
30
|
|
|
Coupon::class => CouponPolicy::class, |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* bootstrap, add routes. |
|
35
|
|
|
* |
|
36
|
|
|
* @param GateContract $gate |
|
37
|
|
|
*/ |
|
38
|
14 |
|
public function boot(GateContract $gate) |
|
39
|
|
|
{ |
|
40
|
14 |
|
if (!class_exists('CreateDiscountTables')) { |
|
41
|
1 |
|
$timestamp = date('Y_m_d_His', time()); |
|
42
|
1 |
|
$this->publishes([ |
|
43
|
1 |
|
__DIR__.'/../../migrations/create_discount_tables.php.stub' => database_path()."/migrations/{$timestamp}_create_discount_tables.php", |
|
44
|
1 |
|
], 'migrations'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
14 |
|
$this->registerPolicies($gate); |
|
48
|
14 |
|
} |
|
49
|
|
|
|
|
50
|
14 |
|
private function registerPolicies(GateContract $gate) |
|
51
|
|
|
{ |
|
52
|
14 |
|
foreach ($this->policies as $key => $value) { |
|
53
|
14 |
|
$gate->policy($key, $value); |
|
54
|
|
|
} |
|
55
|
14 |
|
} |
|
56
|
|
|
|
|
57
|
14 |
|
public function register() |
|
58
|
|
|
{ |
|
59
|
14 |
|
$this->app->bind( |
|
60
|
14 |
|
ItemTotalRuleChecker::class, |
|
61
|
14 |
|
ItemTotalRuleChecker::class |
|
62
|
|
|
); |
|
63
|
14 |
|
$this->app->alias(ItemTotalRuleChecker::class, ItemTotalRuleChecker::TYPE); |
|
64
|
|
|
|
|
65
|
14 |
|
$this->app->bind( |
|
66
|
14 |
|
CartQuantityRuleChecker::class, |
|
67
|
14 |
|
CartQuantityRuleChecker::class |
|
68
|
|
|
); |
|
69
|
14 |
|
$this->app->alias(CartQuantityRuleChecker::class, CartQuantityRuleChecker::TYPE); |
|
70
|
|
|
|
|
71
|
14 |
|
$this->app->bind( |
|
72
|
14 |
|
OrderFixedDiscountAction::class, |
|
73
|
14 |
|
OrderFixedDiscountAction::class |
|
74
|
|
|
); |
|
75
|
14 |
|
$this->app->alias(OrderFixedDiscountAction::class, OrderFixedDiscountAction::TYPE); |
|
76
|
|
|
|
|
77
|
14 |
|
$this->app->bind( |
|
78
|
14 |
|
OrderPercentageDiscountAction::class, |
|
79
|
14 |
|
OrderPercentageDiscountAction::class |
|
80
|
|
|
); |
|
81
|
14 |
|
$this->app->alias(OrderPercentageDiscountAction::class, OrderPercentageDiscountAction::TYPE); |
|
82
|
14 |
|
$this->app->bind(DiscountRepository::class, DiscountRepositoryEloquent::class); |
|
83
|
14 |
|
$this->app->bind(CouponRepository::class, CouponRepositoryEloquent::class); |
|
84
|
14 |
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|