1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\Traits\HasBalance; |
8
|
|
|
use Application\Traits\HasProductType; |
9
|
|
|
use Application\Traits\HasQuantity; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
use Ecodev\Felix\Model\Traits\HasName; |
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
|
17 |
|
public function __construct() |
68
|
|
|
{ |
69
|
17 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @API\Exclude |
73
|
|
|
*/ |
74
|
12 |
|
public function setOrder(Order $order): void |
75
|
|
|
{ |
76
|
12 |
|
if ($this->order) { |
77
|
1 |
|
$this->order->orderLineRemoved($this); |
78
|
|
|
} |
79
|
|
|
|
80
|
12 |
|
$this->order = $order; |
81
|
12 |
|
$order->orderLineAdded($this); |
82
|
12 |
|
} |
83
|
|
|
|
84
|
1 |
|
public function getOrder(): Order |
85
|
|
|
{ |
86
|
1 |
|
return $this->order; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get related product, if it still exists in DB |
91
|
|
|
*/ |
92
|
18 |
|
public function getProduct(): ?Product |
93
|
|
|
{ |
94
|
18 |
|
return $this->product; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set related product |
99
|
|
|
*/ |
100
|
14 |
|
public function setProduct(?Product $product): void |
101
|
|
|
{ |
102
|
14 |
|
$this->product = $product; |
103
|
14 |
|
if ($product) { |
104
|
14 |
|
$this->subscription = null; |
105
|
14 |
|
$this->setName($product->getName()); |
106
|
|
|
} |
107
|
14 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get related subscription, if it still exists in DB |
111
|
|
|
*/ |
112
|
17 |
|
public function getSubscription(): ?Subscription |
113
|
|
|
{ |
114
|
17 |
|
return $this->subscription; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Set related subscription |
119
|
|
|
*/ |
120
|
7 |
|
public function setSubscription(?Subscription $subscription): void |
121
|
|
|
{ |
122
|
7 |
|
$this->subscription = $subscription; |
123
|
|
|
|
124
|
7 |
|
if ($subscription) { |
125
|
7 |
|
$this->product = null; |
126
|
7 |
|
$this->setName($subscription->getName()); |
127
|
|
|
} |
128
|
7 |
|
} |
129
|
|
|
|
130
|
1 |
|
public function setDonation(): void |
131
|
|
|
{ |
132
|
1 |
|
$this->product = null; |
133
|
1 |
|
$this->subscription = null; |
134
|
1 |
|
$this->setName('Don'); |
135
|
1 |
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Additional emails for subscription for a company |
139
|
|
|
* |
140
|
|
|
* @return string[] |
141
|
|
|
*/ |
142
|
17 |
|
public function getAdditionalEmails(): array |
143
|
|
|
{ |
144
|
17 |
|
return $this->additionalEmails; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Additional emails for subscription for a company |
149
|
|
|
* |
150
|
|
|
* @param string[] $additionalEmails |
151
|
|
|
*/ |
152
|
17 |
|
public function setAdditionalEmails(array $additionalEmails): void |
153
|
|
|
{ |
154
|
17 |
|
$this->additionalEmails = $additionalEmails; |
155
|
17 |
|
} |
156
|
|
|
} |
157
|
|
|
|