commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
DiscountCodeDraftModel.php
1<?php
2
3declare(strict_types=1);
10
20use DateTimeImmutable;
21use stdClass;
22
27{
32 protected $key;
33
38 protected $name;
39
44 protected $description;
45
50 protected $code;
51
56 protected $cartDiscounts;
57
62 protected $cartPredicate;
63
68 protected $isActive;
69
75
81
86 protected $custom;
87
92 protected $groups;
93
98 protected $validFrom;
99
104 protected $validUntil;
105
106
110 public function __construct(
111 ?string $key = null,
112 ?LocalizedString $name = null,
114 ?string $code = null,
116 ?string $cartPredicate = null,
117 ?bool $isActive = null,
118 ?int $maxApplications = null,
119 ?int $maxApplicationsPerCustomer = null,
121 ?array $groups = null,
122 ?DateTimeImmutable $validFrom = null,
123 ?DateTimeImmutable $validUntil = null
124 ) {
125 $this->key = $key;
126 $this->name = $name;
127 $this->description = $description;
128 $this->code = $code;
129 $this->cartDiscounts = $cartDiscounts;
130 $this->cartPredicate = $cartPredicate;
131 $this->isActive = $isActive;
132 $this->maxApplications = $maxApplications;
133 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
134 $this->custom = $custom;
135 $this->groups = $groups;
136 $this->validFrom = $validFrom;
137 $this->validUntil = $validUntil;
138 }
139
148 public function getKey()
149 {
150 if (is_null($this->key)) {
152 $data = $this->raw(self::FIELD_KEY);
153 if (is_null($data)) {
154 return null;
155 }
156 $this->key = (string) $data;
157 }
158
159 return $this->key;
160 }
161
168 public function getName()
169 {
170 if (is_null($this->name)) {
172 $data = $this->raw(self::FIELD_NAME);
173 if (is_null($data)) {
174 return null;
175 }
176
177 $this->name = LocalizedStringModel::of($data);
178 }
179
180 return $this->name;
181 }
182
189 public function getDescription()
190 {
191 if (is_null($this->description)) {
193 $data = $this->raw(self::FIELD_DESCRIPTION);
194 if (is_null($data)) {
195 return null;
196 }
197
198 $this->description = LocalizedStringModel::of($data);
199 }
200
201 return $this->description;
202 }
203
212 public function getCode()
213 {
214 if (is_null($this->code)) {
216 $data = $this->raw(self::FIELD_CODE);
217 if (is_null($data)) {
218 return null;
219 }
220 $this->code = (string) $data;
221 }
222
223 return $this->code;
224 }
225
232 public function getCartDiscounts()
233 {
234 if (is_null($this->cartDiscounts)) {
236 $data = $this->raw(self::FIELD_CART_DISCOUNTS);
237 if (is_null($data)) {
238 return null;
239 }
240 $this->cartDiscounts = CartDiscountResourceIdentifierCollection::fromArray($data);
241 }
242
244 }
245
252 public function getCartPredicate()
253 {
254 if (is_null($this->cartPredicate)) {
256 $data = $this->raw(self::FIELD_CART_PREDICATE);
257 if (is_null($data)) {
258 return null;
259 }
260 $this->cartPredicate = (string) $data;
261 }
262
264 }
265
272 public function getIsActive()
273 {
274 if (is_null($this->isActive)) {
276 $data = $this->raw(self::FIELD_IS_ACTIVE);
277 if (is_null($data)) {
278 return null;
279 }
280 $this->isActive = (bool) $data;
281 }
282
283 return $this->isActive;
284 }
285
295 public function getMaxApplications()
296 {
297 if (is_null($this->maxApplications)) {
299 $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
300 if (is_null($data)) {
301 return null;
302 }
303 $this->maxApplications = (int) $data;
304 }
305
307 }
308
319 {
320 if (is_null($this->maxApplicationsPerCustomer)) {
322 $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
323 if (is_null($data)) {
324 return null;
325 }
326 $this->maxApplicationsPerCustomer = (int) $data;
327 }
328
330 }
331
338 public function getCustom()
339 {
340 if (is_null($this->custom)) {
342 $data = $this->raw(self::FIELD_CUSTOM);
343 if (is_null($data)) {
344 return null;
345 }
346
347 $this->custom = CustomFieldsDraftModel::of($data);
348 }
349
350 return $this->custom;
351 }
352
359 public function getGroups()
360 {
361 if (is_null($this->groups)) {
363 $data = $this->raw(self::FIELD_GROUPS);
364 if (is_null($data)) {
365 return null;
366 }
367 $this->groups = $data;
368 }
369
370 return $this->groups;
371 }
372
379 public function getValidFrom()
380 {
381 if (is_null($this->validFrom)) {
383 $data = $this->raw(self::FIELD_VALID_FROM);
384 if (is_null($data)) {
385 return null;
386 }
387 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
388 if (false === $data) {
389 return null;
390 }
391 $this->validFrom = $data;
392 }
393
394 return $this->validFrom;
395 }
396
403 public function getValidUntil()
404 {
405 if (is_null($this->validUntil)) {
407 $data = $this->raw(self::FIELD_VALID_UNTIL);
408 if (is_null($data)) {
409 return null;
410 }
411 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
412 if (false === $data) {
413 return null;
414 }
415 $this->validUntil = $data;
416 }
417
418 return $this->validUntil;
419 }
420
421
425 public function setKey(?string $key): void
426 {
427 $this->key = $key;
428 }
429
433 public function setName(?LocalizedString $name): void
434 {
435 $this->name = $name;
436 }
437
442 {
443 $this->description = $description;
444 }
445
449 public function setCode(?string $code): void
450 {
451 $this->code = $code;
452 }
453
458 {
459 $this->cartDiscounts = $cartDiscounts;
460 }
461
465 public function setCartPredicate(?string $cartPredicate): void
466 {
467 $this->cartPredicate = $cartPredicate;
468 }
469
473 public function setIsActive(?bool $isActive): void
474 {
475 $this->isActive = $isActive;
476 }
477
481 public function setMaxApplications(?int $maxApplications): void
482 {
483 $this->maxApplications = $maxApplications;
484 }
485
490 {
491 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
492 }
493
497 public function setCustom(?CustomFieldsDraft $custom): void
498 {
499 $this->custom = $custom;
500 }
501
505 public function setGroups(?array $groups): void
506 {
507 $this->groups = $groups;
508 }
509
513 public function setValidFrom(?DateTimeImmutable $validFrom): void
514 {
515 $this->validFrom = $validFrom;
516 }
517
521 public function setValidUntil(?DateTimeImmutable $validUntil): void
522 {
523 $this->validUntil = $validUntil;
524 }
525
526
527 #[\ReturnTypeWillChange]
528 public function jsonSerialize()
529 {
530 $data = $this->toArray();
531 if (isset($data[DiscountCodeDraft::FIELD_VALID_FROM]) && $data[DiscountCodeDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
532 $data[DiscountCodeDraft::FIELD_VALID_FROM] = $data[DiscountCodeDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
533 }
534
535 if (isset($data[DiscountCodeDraft::FIELD_VALID_UNTIL]) && $data[DiscountCodeDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
536 $data[DiscountCodeDraft::FIELD_VALID_UNTIL] = $data[DiscountCodeDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
537 }
538 return (object) $data;
539 }
540}
setCartDiscounts(?CartDiscountResourceIdentifierCollection $cartDiscounts)
__construct(?string $key=null, ?LocalizedString $name=null, ?LocalizedString $description=null, ?string $code=null, ?CartDiscountResourceIdentifierCollection $cartDiscounts=null, ?string $cartPredicate=null, ?bool $isActive=null, ?int $maxApplications=null, ?int $maxApplicationsPerCustomer=null, ?CustomFieldsDraft $custom=null, ?array $groups=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null)