1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WSW\SiftScience\Support\Traits\Transformers; |
4
|
|
|
|
5
|
|
|
use WSW\SiftScience\Collections\Items; |
6
|
|
|
use WSW\SiftScience\Collections\PaymentMethods; |
7
|
|
|
use WSW\SiftScience\Collections\Promotions; |
8
|
|
|
use WSW\SiftScience\Entities\Address; |
9
|
|
|
use WSW\SiftScience\Entities\CreditPoint; |
10
|
|
|
use WSW\SiftScience\Entities\Discount; |
11
|
|
|
use WSW\SiftScience\Transformers\Entities\AddressTransformer; |
12
|
|
|
use WSW\SiftScience\Transformers\Entities\CreditPointTransformer; |
13
|
|
|
use WSW\SiftScience\Transformers\Entities\DiscountTransformer; |
14
|
|
|
use WSW\SiftScience\Transformers\Entities\ItemTransformer; |
15
|
|
|
use WSW\SiftScience\Transformers\Entities\PaymentMethodTransformer; |
16
|
|
|
use WSW\SiftScience\Transformers\Entities\PromotionTransformer; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Trait Relationships |
20
|
|
|
* |
21
|
|
|
* @package WSW\SiftScience\Support\Traits\Transformers |
22
|
|
|
* @author Ronaldo Matos Rodrigues <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
trait Relationships |
25
|
|
|
{ |
26
|
|
|
use Fractal; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param $address|null |
30
|
|
|
* |
31
|
|
|
* @return array|null |
32
|
|
|
*/ |
33
|
13 |
|
public function address($address = null) |
34
|
|
|
{ |
35
|
13 |
|
return (!$address instanceof Address) |
36
|
12 |
|
? null |
37
|
13 |
|
: $this->loadItem($address, new AddressTransformer)->toArray(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Discount|null $discount |
42
|
|
|
* |
43
|
|
|
* @return array|null |
44
|
|
|
*/ |
45
|
3 |
|
public function discount($discount = null) |
46
|
|
|
{ |
47
|
3 |
|
return (!$discount instanceof Discount) |
48
|
2 |
|
? null |
49
|
3 |
|
: $this->loadItem($discount, new DiscountTransformer)->toArray(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param CreditPoint|null $creditPoint |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
3 |
|
public function creditPoint($creditPoint = null) |
58
|
|
|
{ |
59
|
3 |
|
return (!$creditPoint instanceof CreditPoint) |
60
|
2 |
|
? null |
61
|
3 |
|
: $this->loadItem($creditPoint, new CreditPointTransformer)->toArray(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param PaymentMethods|null $collection |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
11 |
|
public function paymentMethods($collection = null) |
70
|
|
|
{ |
71
|
11 |
|
return (!$collection instanceof PaymentMethods) |
72
|
1 |
|
? null |
73
|
11 |
|
: $this->loadCollection($collection->getValues(), new PaymentMethodTransformer)->toArray(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param Items|null $items |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
6 |
|
public function items($items) |
82
|
|
|
{ |
83
|
6 |
|
return (!$items instanceof Items) |
84
|
1 |
|
? null |
85
|
6 |
|
: $this->loadCollection($items->getValues(), new ItemTransformer)->toArray(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param Promotions|null $promotions |
90
|
|
|
* |
91
|
|
|
* @return array|null |
92
|
|
|
*/ |
93
|
6 |
|
public function promotions($promotions = null) |
94
|
|
|
{ |
95
|
6 |
|
return (!$promotions instanceof Promotions) |
96
|
1 |
|
? null |
97
|
6 |
|
: $this->loadCollection($promotions->getValues(), new PromotionTransformer)->toArray(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|