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
147 public function getKey()
148 {
149 if (is_null($this->key)) {
151 $data = $this->raw(self::FIELD_KEY);
152 if (is_null($data)) {
153 return null;
154 }
155 $this->key = (string) $data;
156 }
157
158 return $this->key;
159 }
160
167 public function getName()
168 {
169 if (is_null($this->name)) {
171 $data = $this->raw(self::FIELD_NAME);
172 if (is_null($data)) {
173 return null;
174 }
175
176 $this->name = LocalizedStringModel::of($data);
177 }
178
179 return $this->name;
180 }
181
188 public function getDescription()
189 {
190 if (is_null($this->description)) {
192 $data = $this->raw(self::FIELD_DESCRIPTION);
193 if (is_null($data)) {
194 return null;
195 }
196
197 $this->description = LocalizedStringModel::of($data);
198 }
199
200 return $this->description;
201 }
202
210 public function getCode()
211 {
212 if (is_null($this->code)) {
214 $data = $this->raw(self::FIELD_CODE);
215 if (is_null($data)) {
216 return null;
217 }
218 $this->code = (string) $data;
219 }
220
221 return $this->code;
222 }
223
230 public function getCartDiscounts()
231 {
232 if (is_null($this->cartDiscounts)) {
234 $data = $this->raw(self::FIELD_CART_DISCOUNTS);
235 if (is_null($data)) {
236 return null;
237 }
238 $this->cartDiscounts = CartDiscountResourceIdentifierCollection::fromArray($data);
239 }
240
242 }
243
250 public function getCartPredicate()
251 {
252 if (is_null($this->cartPredicate)) {
254 $data = $this->raw(self::FIELD_CART_PREDICATE);
255 if (is_null($data)) {
256 return null;
257 }
258 $this->cartPredicate = (string) $data;
259 }
260
262 }
263
270 public function getIsActive()
271 {
272 if (is_null($this->isActive)) {
274 $data = $this->raw(self::FIELD_IS_ACTIVE);
275 if (is_null($data)) {
276 return null;
277 }
278 $this->isActive = (bool) $data;
279 }
280
281 return $this->isActive;
282 }
283
292 public function getMaxApplications()
293 {
294 if (is_null($this->maxApplications)) {
296 $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
297 if (is_null($data)) {
298 return null;
299 }
300 $this->maxApplications = (int) $data;
301 }
302
304 }
305
315 {
316 if (is_null($this->maxApplicationsPerCustomer)) {
318 $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
319 if (is_null($data)) {
320 return null;
321 }
322 $this->maxApplicationsPerCustomer = (int) $data;
323 }
324
326 }
327
334 public function getCustom()
335 {
336 if (is_null($this->custom)) {
338 $data = $this->raw(self::FIELD_CUSTOM);
339 if (is_null($data)) {
340 return null;
341 }
342
343 $this->custom = CustomFieldsDraftModel::of($data);
344 }
345
346 return $this->custom;
347 }
348
355 public function getGroups()
356 {
357 if (is_null($this->groups)) {
359 $data = $this->raw(self::FIELD_GROUPS);
360 if (is_null($data)) {
361 return null;
362 }
363 $this->groups = $data;
364 }
365
366 return $this->groups;
367 }
368
375 public function getValidFrom()
376 {
377 if (is_null($this->validFrom)) {
379 $data = $this->raw(self::FIELD_VALID_FROM);
380 if (is_null($data)) {
381 return null;
382 }
383 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
384 if (false === $data) {
385 return null;
386 }
387 $this->validFrom = $data;
388 }
389
390 return $this->validFrom;
391 }
392
399 public function getValidUntil()
400 {
401 if (is_null($this->validUntil)) {
403 $data = $this->raw(self::FIELD_VALID_UNTIL);
404 if (is_null($data)) {
405 return null;
406 }
407 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
408 if (false === $data) {
409 return null;
410 }
411 $this->validUntil = $data;
412 }
413
414 return $this->validUntil;
415 }
416
417
421 public function setKey(?string $key): void
422 {
423 $this->key = $key;
424 }
425
429 public function setName(?LocalizedString $name): void
430 {
431 $this->name = $name;
432 }
433
438 {
439 $this->description = $description;
440 }
441
445 public function setCode(?string $code): void
446 {
447 $this->code = $code;
448 }
449
454 {
455 $this->cartDiscounts = $cartDiscounts;
456 }
457
461 public function setCartPredicate(?string $cartPredicate): void
462 {
463 $this->cartPredicate = $cartPredicate;
464 }
465
469 public function setIsActive(?bool $isActive): void
470 {
471 $this->isActive = $isActive;
472 }
473
477 public function setMaxApplications(?int $maxApplications): void
478 {
479 $this->maxApplications = $maxApplications;
480 }
481
486 {
487 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
488 }
489
493 public function setCustom(?CustomFieldsDraft $custom): void
494 {
495 $this->custom = $custom;
496 }
497
501 public function setGroups(?array $groups): void
502 {
503 $this->groups = $groups;
504 }
505
509 public function setValidFrom(?DateTimeImmutable $validFrom): void
510 {
511 $this->validFrom = $validFrom;
512 }
513
517 public function setValidUntil(?DateTimeImmutable $validUntil): void
518 {
519 $this->validUntil = $validUntil;
520 }
521
522
523 #[\ReturnTypeWillChange]
524 public function jsonSerialize()
525 {
526 $data = $this->toArray();
527 if (isset($data[DiscountCodeDraft::FIELD_VALID_FROM]) && $data[DiscountCodeDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
528 $data[DiscountCodeDraft::FIELD_VALID_FROM] = $data[DiscountCodeDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
529 }
530
531 if (isset($data[DiscountCodeDraft::FIELD_VALID_UNTIL]) && $data[DiscountCodeDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
532 $data[DiscountCodeDraft::FIELD_VALID_UNTIL] = $data[DiscountCodeDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
533 }
534 return (object) $data;
535 }
536}
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)