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
291 public function getMaxApplications()
292 {
293 if (is_null($this->maxApplications)) {
295 $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
296 if (is_null($data)) {
297 return null;
298 }
299 $this->maxApplications = (int) $data;
300 }
301
303 }
304
313 {
314 if (is_null($this->maxApplicationsPerCustomer)) {
316 $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
317 if (is_null($data)) {
318 return null;
319 }
320 $this->maxApplicationsPerCustomer = (int) $data;
321 }
322
324 }
325
332 public function getCustom()
333 {
334 if (is_null($this->custom)) {
336 $data = $this->raw(self::FIELD_CUSTOM);
337 if (is_null($data)) {
338 return null;
339 }
340
341 $this->custom = CustomFieldsDraftModel::of($data);
342 }
343
344 return $this->custom;
345 }
346
353 public function getGroups()
354 {
355 if (is_null($this->groups)) {
357 $data = $this->raw(self::FIELD_GROUPS);
358 if (is_null($data)) {
359 return null;
360 }
361 $this->groups = $data;
362 }
363
364 return $this->groups;
365 }
366
373 public function getValidFrom()
374 {
375 if (is_null($this->validFrom)) {
377 $data = $this->raw(self::FIELD_VALID_FROM);
378 if (is_null($data)) {
379 return null;
380 }
381 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
382 if (false === $data) {
383 return null;
384 }
385 $this->validFrom = $data;
386 }
387
388 return $this->validFrom;
389 }
390
397 public function getValidUntil()
398 {
399 if (is_null($this->validUntil)) {
401 $data = $this->raw(self::FIELD_VALID_UNTIL);
402 if (is_null($data)) {
403 return null;
404 }
405 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
406 if (false === $data) {
407 return null;
408 }
409 $this->validUntil = $data;
410 }
411
412 return $this->validUntil;
413 }
414
415
419 public function setKey(?string $key): void
420 {
421 $this->key = $key;
422 }
423
427 public function setName(?LocalizedString $name): void
428 {
429 $this->name = $name;
430 }
431
436 {
437 $this->description = $description;
438 }
439
443 public function setCode(?string $code): void
444 {
445 $this->code = $code;
446 }
447
452 {
453 $this->cartDiscounts = $cartDiscounts;
454 }
455
459 public function setCartPredicate(?string $cartPredicate): void
460 {
461 $this->cartPredicate = $cartPredicate;
462 }
463
467 public function setIsActive(?bool $isActive): void
468 {
469 $this->isActive = $isActive;
470 }
471
475 public function setMaxApplications(?int $maxApplications): void
476 {
477 $this->maxApplications = $maxApplications;
478 }
479
484 {
485 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
486 }
487
491 public function setCustom(?CustomFieldsDraft $custom): void
492 {
493 $this->custom = $custom;
494 }
495
499 public function setGroups(?array $groups): void
500 {
501 $this->groups = $groups;
502 }
503
507 public function setValidFrom(?DateTimeImmutable $validFrom): void
508 {
509 $this->validFrom = $validFrom;
510 }
511
515 public function setValidUntil(?DateTimeImmutable $validUntil): void
516 {
517 $this->validUntil = $validUntil;
518 }
519
520
521 #[\ReturnTypeWillChange]
522 public function jsonSerialize()
523 {
524 $data = $this->toArray();
525 if (isset($data[DiscountCodeDraft::FIELD_VALID_FROM]) && $data[DiscountCodeDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
526 $data[DiscountCodeDraft::FIELD_VALID_FROM] = $data[DiscountCodeDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
527 }
528
529 if (isset($data[DiscountCodeDraft::FIELD_VALID_UNTIL]) && $data[DiscountCodeDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
530 $data[DiscountCodeDraft::FIELD_VALID_UNTIL] = $data[DiscountCodeDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
531 }
532 return (object) $data;
533 }
534}
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)