commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
DiscountCodeImportModel.php
1<?php
2
3declare(strict_types=1);
10
22use DateTimeImmutable;
23use stdClass;
24
29{
34 protected $key;
35
40 protected $name;
41
46 protected $description;
47
52 protected $code;
53
58 protected $cartDiscounts;
59
64 protected $cartPredicate;
65
70 protected $isActive;
71
77
83
88 protected $groups;
89
94 protected $validFrom;
95
100 protected $validUntil;
101
106 protected $custom;
107
108
112 public function __construct(
113 ?string $key = null,
114 ?LocalizedString $name = null,
116 ?string $code = null,
118 ?string $cartPredicate = null,
119 ?bool $isActive = null,
120 ?int $maxApplications = null,
121 ?int $maxApplicationsPerCustomer = null,
122 ?array $groups = null,
123 ?DateTimeImmutable $validFrom = null,
124 ?DateTimeImmutable $validUntil = null,
125 ?Custom $custom = null
126 ) {
127 $this->key = $key;
128 $this->name = $name;
129 $this->description = $description;
130 $this->code = $code;
131 $this->cartDiscounts = $cartDiscounts;
132 $this->cartPredicate = $cartPredicate;
133 $this->isActive = $isActive;
134 $this->maxApplications = $maxApplications;
135 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
136 $this->groups = $groups;
137 $this->validFrom = $validFrom;
138 $this->validUntil = $validUntil;
139 $this->custom = $custom;
140 }
141
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
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 = CartDiscountKeyReferenceCollection::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
290 public function getMaxApplications()
291 {
292 if (is_null($this->maxApplications)) {
294 $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
295 if (is_null($data)) {
296 return null;
297 }
298 $this->maxApplications = (int) $data;
299 }
300
302 }
303
311 {
312 if (is_null($this->maxApplicationsPerCustomer)) {
314 $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
315 if (is_null($data)) {
316 return null;
317 }
318 $this->maxApplicationsPerCustomer = (int) $data;
319 }
320
322 }
323
330 public function getGroups()
331 {
332 if (is_null($this->groups)) {
334 $data = $this->raw(self::FIELD_GROUPS);
335 if (is_null($data)) {
336 return null;
337 }
338 $this->groups = $data;
339 }
340
341 return $this->groups;
342 }
343
350 public function getValidFrom()
351 {
352 if (is_null($this->validFrom)) {
354 $data = $this->raw(self::FIELD_VALID_FROM);
355 if (is_null($data)) {
356 return null;
357 }
358 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
359 if (false === $data) {
360 return null;
361 }
362 $this->validFrom = $data;
363 }
364
365 return $this->validFrom;
366 }
367
374 public function getValidUntil()
375 {
376 if (is_null($this->validUntil)) {
378 $data = $this->raw(self::FIELD_VALID_UNTIL);
379 if (is_null($data)) {
380 return null;
381 }
382 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
383 if (false === $data) {
384 return null;
385 }
386 $this->validUntil = $data;
387 }
388
389 return $this->validUntil;
390 }
391
398 public function getCustom()
399 {
400 if (is_null($this->custom)) {
402 $data = $this->raw(self::FIELD_CUSTOM);
403 if (is_null($data)) {
404 return null;
405 }
406
407 $this->custom = CustomModel::of($data);
408 }
409
410 return $this->custom;
411 }
412
413
417 public function setKey(?string $key): void
418 {
419 $this->key = $key;
420 }
421
425 public function setName(?LocalizedString $name): void
426 {
427 $this->name = $name;
428 }
429
434 {
435 $this->description = $description;
436 }
437
441 public function setCode(?string $code): void
442 {
443 $this->code = $code;
444 }
445
450 {
451 $this->cartDiscounts = $cartDiscounts;
452 }
453
457 public function setCartPredicate(?string $cartPredicate): void
458 {
459 $this->cartPredicate = $cartPredicate;
460 }
461
465 public function setIsActive(?bool $isActive): void
466 {
467 $this->isActive = $isActive;
468 }
469
473 public function setMaxApplications(?int $maxApplications): void
474 {
475 $this->maxApplications = $maxApplications;
476 }
477
482 {
483 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
484 }
485
489 public function setGroups(?array $groups): void
490 {
491 $this->groups = $groups;
492 }
493
497 public function setValidFrom(?DateTimeImmutable $validFrom): void
498 {
499 $this->validFrom = $validFrom;
500 }
501
505 public function setValidUntil(?DateTimeImmutable $validUntil): void
506 {
507 $this->validUntil = $validUntil;
508 }
509
513 public function setCustom(?Custom $custom): void
514 {
515 $this->custom = $custom;
516 }
517
518
519 #[\ReturnTypeWillChange]
520 public function jsonSerialize()
521 {
522 $data = $this->toArray();
523 if (isset($data[DiscountCodeImport::FIELD_VALID_FROM]) && $data[DiscountCodeImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
524 $data[DiscountCodeImport::FIELD_VALID_FROM] = $data[DiscountCodeImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
525 }
526
527 if (isset($data[DiscountCodeImport::FIELD_VALID_UNTIL]) && $data[DiscountCodeImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
528 $data[DiscountCodeImport::FIELD_VALID_UNTIL] = $data[DiscountCodeImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
529 }
530 return (object) $data;
531 }
532}
setCartDiscounts(?CartDiscountKeyReferenceCollection $cartDiscounts)
__construct(?string $key=null, ?LocalizedString $name=null, ?LocalizedString $description=null, ?string $code=null, ?CartDiscountKeyReferenceCollection $cartDiscounts=null, ?string $cartPredicate=null, ?bool $isActive=null, ?int $maxApplications=null, ?int $maxApplicationsPerCustomer=null, ?array $groups=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?Custom $custom=null)