1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\Traits\HasBalance; |
8
|
|
|
use Application\Traits\HasName; |
9
|
|
|
use Application\Traits\HasProductType; |
10
|
|
|
use Application\Traits\HasQuantity; |
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
12
|
|
|
use GraphQL\Doctrine\Annotation as API; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A single line in the shopping cart when making an order |
16
|
|
|
* |
17
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\OrderLineRepository") |
18
|
|
|
*/ |
19
|
|
|
class OrderLine extends AbstractModel |
20
|
|
|
{ |
21
|
|
|
use HasName; |
22
|
|
|
use HasQuantity; |
23
|
|
|
use HasBalance; |
24
|
|
|
use HasProductType; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Additional emails for subscription for a company |
28
|
|
|
* |
29
|
|
|
* @var string[] |
30
|
|
|
* @ORM\Column(type="json", options={"default" = "[]"}) |
31
|
|
|
*/ |
32
|
|
|
private $additionalEmails = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Order |
36
|
|
|
* |
37
|
|
|
* @ORM\ManyToOne(targetEntity="Order", inversedBy="orderLines") |
38
|
|
|
* @ORM\JoinColumns({ |
39
|
|
|
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE") |
40
|
|
|
* }) |
41
|
|
|
*/ |
42
|
|
|
private $order; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var null|Product |
46
|
|
|
* |
47
|
|
|
* @ORM\ManyToOne(targetEntity="Product") |
48
|
|
|
* @ORM\JoinColumns({ |
49
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
50
|
|
|
* }) |
51
|
|
|
*/ |
52
|
|
|
private $product; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var null|Subscription |
56
|
|
|
* |
57
|
|
|
* @ORM\ManyToOne(targetEntity="Subscription") |
58
|
|
|
* @ORM\JoinColumns({ |
59
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL") |
60
|
|
|
* }) |
61
|
|
|
*/ |
62
|
|
|
private $subscription; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Constructor |
66
|
|
|
*/ |
67
|
16 |
|
public function __construct() |
68
|
|
|
{ |
69
|
16 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @API\Exclude |
73
|
|
|
* |
74
|
|
|
* @param Order $order |
75
|
|
|
*/ |
76
|
12 |
|
public function setOrder(Order $order): void |
77
|
|
|
{ |
78
|
12 |
|
if ($this->order) { |
79
|
1 |
|
$this->order->orderLineRemoved($this); |
80
|
|
|
} |
81
|
|
|
|
82
|
12 |
|
$this->order = $order; |
83
|
12 |
|
$order->orderLineAdded($this); |
84
|
12 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return Order |
88
|
|
|
*/ |
89
|
1 |
|
public function getOrder(): Order |
90
|
|
|
{ |
91
|
1 |
|
return $this->order; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get related product, if it still exists in DB |
96
|
|
|
* |
97
|
|
|
* @return null|Product |
98
|
|
|
*/ |
99
|
17 |
|
public function getProduct(): ?Product |
100
|
|
|
{ |
101
|
17 |
|
return $this->product; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Set related product |
106
|
|
|
* |
107
|
|
|
* @param null|Product $product |
108
|
|
|
*/ |
109
|
13 |
|
public function setProduct(?Product $product): void |
110
|
|
|
{ |
111
|
13 |
|
$this->product = $product; |
112
|
13 |
|
if ($product) { |
113
|
13 |
|
$this->subscription = null; |
114
|
13 |
|
$this->setName($product->getName()); |
115
|
|
|
} |
116
|
13 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get related subscription, if it still exists in DB |
120
|
|
|
* |
121
|
|
|
* @return null|Subscription |
122
|
|
|
*/ |
123
|
12 |
|
public function getSubscription(): ?Subscription |
124
|
|
|
{ |
125
|
12 |
|
return $this->subscription; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Set related subscription |
130
|
|
|
* |
131
|
|
|
* @param null|Subscription $subscription |
132
|
|
|
*/ |
133
|
2 |
|
public function setSubscription(?Subscription $subscription): void |
134
|
|
|
{ |
135
|
2 |
|
$this->subscription = $subscription; |
136
|
|
|
|
137
|
2 |
|
if ($subscription) { |
138
|
2 |
|
$this->product = null; |
139
|
2 |
|
$this->setName($subscription->getName()); |
140
|
|
|
} |
141
|
2 |
|
} |
142
|
|
|
|
143
|
1 |
|
public function setDonation(): void |
144
|
|
|
{ |
145
|
1 |
|
$this->product = null; |
146
|
1 |
|
$this->subscription = null; |
147
|
1 |
|
$this->setName('Donation'); |
148
|
1 |
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Additional emails for subscription for a company |
152
|
|
|
* |
153
|
|
|
* @return string[] |
154
|
|
|
*/ |
155
|
16 |
|
public function getAdditionalEmails(): array |
156
|
|
|
{ |
157
|
16 |
|
return $this->additionalEmails; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Additional emails for subscription for a company |
162
|
|
|
* |
163
|
|
|
* @param string[] $additionalEmails |
164
|
|
|
*/ |
165
|
16 |
|
public function setAdditionalEmails(array $additionalEmails): void |
166
|
|
|
{ |
167
|
16 |
|
$this->additionalEmails = $additionalEmails; |
168
|
16 |
|
} |
169
|
|
|
} |
170
|
|
|
|