-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPriceCategory.php
More file actions
216 lines (177 loc) · 4.92 KB
/
PriceCategory.php
File metadata and controls
216 lines (177 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
declare(strict_types=1);
namespace Extcode\CartEvents\Domain\Model;
/*
* This file is part of the package extcode/cart-events.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
use TYPO3\CMS\Extbase\Annotation\ORM\Cascade;
use TYPO3\CMS\Extbase\Annotation\Validate;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
class PriceCategory extends AbstractEntity
{
protected EventDate $eventDate;
#[Validate(['validator' => 'NotEmpty'])]
protected string $sku = '';
#[Validate(['validator' => 'NotEmpty'])]
protected string $title = '';
protected float $price = 0.0;
/**
* @var ObjectStorage<SpecialPrice>
*/
#[Cascade(['value' => 'remove'])]
protected ObjectStorage $specialPrices;
protected int $seatsNumber = 0;
protected int $seatsTaken = 0;
public function getSku(): string
{
return $this->sku;
}
public function setSku(string $sku): void
{
$this->sku = $sku;
}
public function getEventDate(): EventDate
{
return $this->eventDate;
}
public function setEventDate(EventDate $eventDate): void
{
$this->eventDate = $eventDate;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getPrice(): float
{
return $this->price;
}
public function setPrice(float $price): void
{
$this->price = $price;
}
/**
* @return ObjectStorage<SpecialPrice>
*/
public function getSpecialPrices(): ?ObjectStorage
{
return $this->specialPrices;
}
public function addSpecialPrice(SpecialPrice $specialPrice): void
{
$this->specialPrices->attach($specialPrice);
}
public function removeSpecialPrice(SpecialPrice $specialPrice): void
{
$this->specialPrices->detach($specialPrice);
}
public function setSpecialPrices(ObjectStorage $specialPrices): void
{
$this->specialPrices = $specialPrices;
}
public function getSeatsNumber(): int
{
return $this->seatsNumber;
}
public function setSeatsNumber(int $seatsNumber): void
{
$this->seatsNumber = $seatsNumber;
}
public function getSeatsTaken(): int
{
return $this->seatsTaken;
}
public function setSeatsTaken(int $seatsTaken): void
{
$this->seatsTaken = $seatsTaken;
}
/**
* Returns the number of available seats in the event if handling the
* number of seats is enabled, otherwise return 0.
*/
public function getSeatsAvailable(): int
{
if (!$this->getEventDate()->isHandleSeats()) {
return 0;
}
return $this->seatsNumber - $this->seatsTaken;
}
/**
* Returns best Special Price
*/
public function getBestSpecialPrice(array $frontendUserGroupIds = []): ?SpecialPrice
{
$bestSpecialPrice = null;
if ($this->specialPrices) {
foreach ($this->specialPrices as $specialPrice) {
if (!isset($bestSpecialPrice) || $specialPrice->getPrice() < $bestSpecialPrice->getPrice()) {
if (!$specialPrice->getFrontendUserGroup()
|| in_array($specialPrice->getFrontendUserGroup()->getUid(), $frontendUserGroupIds)
) {
$bestSpecialPrice = $specialPrice;
}
}
}
}
return $bestSpecialPrice;
}
/**
* Returns price of best Special Price
*/
public function getBestPrice(array $frontendUserGroupIds = []): float
{
$price = $this->getPrice();
$specialPrice = $this->getBestSpecialPrice($frontendUserGroupIds);
if ($specialPrice && $specialPrice->getPrice() < $price) {
return $specialPrice->getPrice();
}
return $price;
}
/**
* TODO
*/
public function getBestPriceCalculated(): float
{
return $this->price;
}
/**
* TODO
*
* Returns best Special Price Percentage Discount
*/
public function getBestSpecialPricePercentageDiscount($frontendUserGroupIds = []): float
{
return 0.0;
}
/**
* TODO
*/
public function isAvailable(): bool
{
if (!$this->getEventDate()->isBookable()) {
return false;
}
if (!$this->getEventDate()->isHandleSeatsInPriceCategory()) {
return $this->getEventDate()->isAvailable();
}
if ($this->getEventDate()->isHandleSeatsInPriceCategory() && $this->getSeatsAvailable()) {
return true;
}
return false;
}
/**
* TODO
*/
public function isBookable(): bool
{
return true;
}
}