|
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\Applicators; |
|
13
|
|
|
|
|
14
|
|
|
use iBrand\Component\Discount\Checkers\ItemTotalRuleChecker; |
|
15
|
|
|
use iBrand\Component\Discount\Contracts\DiscountContract; |
|
16
|
|
|
use iBrand\Component\Discount\Contracts\DiscountSubjectContract; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class DiscountApplicator. |
|
20
|
|
|
*/ |
|
21
|
|
|
class DiscountApplicator |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param DiscountSubjectContract $subject |
|
25
|
|
|
* @param DiscountContract $discount |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function apply(DiscountSubjectContract $subject, DiscountContract $discount) |
|
28
|
|
|
{ |
|
29
|
2 |
|
if (count($discount->getActions())) { |
|
30
|
2 |
|
foreach ($discount->getActions() as $action) { |
|
31
|
2 |
|
$configuration = json_decode($action->configuration, true); |
|
32
|
|
|
|
|
33
|
2 |
|
app($action->type)->execute($subject, $configuration, $discount); |
|
34
|
|
|
|
|
35
|
2 |
|
$discount->setCouponUsed(); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* calculate order discount. |
|
42
|
|
|
* |
|
43
|
|
|
* @param DiscountSubjectContract $subject |
|
44
|
|
|
* @param DiscountContract $discount |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function calculate(DiscountSubjectContract $subject, DiscountContract $discount) |
|
47
|
|
|
{ |
|
48
|
1 |
|
$discount->orderAmountLimit = 0; |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
1 |
|
if (count($discount->getActions())) { |
|
51
|
1 |
|
foreach ($discount->getActions() as $action) { |
|
52
|
1 |
|
$configuration = json_decode($action->configuration, true); |
|
53
|
1 |
|
app($action->type)->calculate($subject, $configuration, $discount); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
foreach ($discount->getRules() as $rule) { |
|
58
|
1 |
|
if (ItemTotalRuleChecker::TYPE == $rule->type) { |
|
59
|
1 |
|
$discount->orderAmountLimit = json_decode($rule->configuration, true)['amount']; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
1 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: