commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ProductDiscountDraftModel.php
1<?php
2
3declare(strict_types=1);
10
17use DateTimeImmutable;
18use stdClass;
19
24{
29 protected $name;
30
35 protected $key;
36
41 protected $description;
42
47 protected $value;
48
53 protected $predicate;
54
59 protected $sortOrder;
60
65 protected $isActive;
66
71 protected $validFrom;
72
77 protected $validUntil;
78
79
83 public function __construct(
84 ?LocalizedString $name = null,
85 ?string $key = null,
88 ?string $predicate = null,
89 ?string $sortOrder = null,
90 ?bool $isActive = null,
91 ?DateTimeImmutable $validFrom = null,
92 ?DateTimeImmutable $validUntil = null
93 ) {
94 $this->name = $name;
95 $this->key = $key;
96 $this->description = $description;
97 $this->value = $value;
98 $this->predicate = $predicate;
99 $this->sortOrder = $sortOrder;
100 $this->isActive = $isActive;
101 $this->validFrom = $validFrom;
102 $this->validUntil = $validUntil;
103 }
104
111 public function getName()
112 {
113 if (is_null($this->name)) {
115 $data = $this->raw(self::FIELD_NAME);
116 if (is_null($data)) {
117 return null;
118 }
119
120 $this->name = LocalizedStringModel::of($data);
121 }
122
123 return $this->name;
124 }
125
132 public function getKey()
133 {
134 if (is_null($this->key)) {
136 $data = $this->raw(self::FIELD_KEY);
137 if (is_null($data)) {
138 return null;
139 }
140 $this->key = (string) $data;
141 }
142
143 return $this->key;
144 }
145
152 public function getDescription()
153 {
154 if (is_null($this->description)) {
156 $data = $this->raw(self::FIELD_DESCRIPTION);
157 if (is_null($data)) {
158 return null;
159 }
160
161 $this->description = LocalizedStringModel::of($data);
162 }
163
164 return $this->description;
165 }
166
173 public function getValue()
174 {
175 if (is_null($this->value)) {
177 $data = $this->raw(self::FIELD_VALUE);
178 if (is_null($data)) {
179 return null;
180 }
182 $this->value = $className::of($data);
183 }
184
185 return $this->value;
186 }
187
194 public function getPredicate()
195 {
196 if (is_null($this->predicate)) {
198 $data = $this->raw(self::FIELD_PREDICATE);
199 if (is_null($data)) {
200 return null;
201 }
202 $this->predicate = (string) $data;
203 }
204
205 return $this->predicate;
206 }
207
215 public function getSortOrder()
216 {
217 if (is_null($this->sortOrder)) {
219 $data = $this->raw(self::FIELD_SORT_ORDER);
220 if (is_null($data)) {
221 return null;
222 }
223 $this->sortOrder = (string) $data;
224 }
225
226 return $this->sortOrder;
227 }
228
235 public function getIsActive()
236 {
237 if (is_null($this->isActive)) {
239 $data = $this->raw(self::FIELD_IS_ACTIVE);
240 if (is_null($data)) {
241 return null;
242 }
243 $this->isActive = (bool) $data;
244 }
245
246 return $this->isActive;
247 }
248
256 public function getValidFrom()
257 {
258 if (is_null($this->validFrom)) {
260 $data = $this->raw(self::FIELD_VALID_FROM);
261 if (is_null($data)) {
262 return null;
263 }
264 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
265 if (false === $data) {
266 return null;
267 }
268 $this->validFrom = $data;
269 }
270
271 return $this->validFrom;
272 }
273
281 public function getValidUntil()
282 {
283 if (is_null($this->validUntil)) {
285 $data = $this->raw(self::FIELD_VALID_UNTIL);
286 if (is_null($data)) {
287 return null;
288 }
289 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
290 if (false === $data) {
291 return null;
292 }
293 $this->validUntil = $data;
294 }
295
296 return $this->validUntil;
297 }
298
299
303 public function setName(?LocalizedString $name): void
304 {
305 $this->name = $name;
306 }
307
311 public function setKey(?string $key): void
312 {
313 $this->key = $key;
314 }
315
320 {
321 $this->description = $description;
322 }
323
328 {
329 $this->value = $value;
330 }
331
335 public function setPredicate(?string $predicate): void
336 {
337 $this->predicate = $predicate;
338 }
339
343 public function setSortOrder(?string $sortOrder): void
344 {
345 $this->sortOrder = $sortOrder;
346 }
347
351 public function setIsActive(?bool $isActive): void
352 {
353 $this->isActive = $isActive;
354 }
355
359 public function setValidFrom(?DateTimeImmutable $validFrom): void
360 {
361 $this->validFrom = $validFrom;
362 }
363
367 public function setValidUntil(?DateTimeImmutable $validUntil): void
368 {
369 $this->validUntil = $validUntil;
370 }
371
372
373 #[\ReturnTypeWillChange]
374 public function jsonSerialize()
375 {
376 $data = $this->toArray();
377 if (isset($data[ProductDiscountDraft::FIELD_VALID_FROM]) && $data[ProductDiscountDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
378 $data[ProductDiscountDraft::FIELD_VALID_FROM] = $data[ProductDiscountDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
379 }
380
381 if (isset($data[ProductDiscountDraft::FIELD_VALID_UNTIL]) && $data[ProductDiscountDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
382 $data[ProductDiscountDraft::FIELD_VALID_UNTIL] = $data[ProductDiscountDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
383 }
384 return (object) $data;
385 }
386}
__construct(?LocalizedString $name=null, ?string $key=null, ?LocalizedString $description=null, ?ProductDiscountValueDraft $value=null, ?string $predicate=null, ?string $sortOrder=null, ?bool $isActive=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null)