commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CartDiscountDraftModel.php
1<?php
2
3declare(strict_types=1);
10
22use DateTimeImmutable;
23use stdClass;
24
29{
34 protected $name;
35
40 protected $key;
41
46 protected $description;
47
52 protected $value;
53
58 protected $cartPredicate;
59
64 protected $target;
65
70 protected $sortOrder;
71
76 protected $stores;
77
82 protected $isActive;
83
88 protected $validFrom;
89
94 protected $validUntil;
95
101
106 protected $stackingMode;
107
112 protected $custom;
113
118 protected $discountGroup;
119
120
124 public function __construct(
125 ?LocalizedString $name = null,
126 ?string $key = null,
129 ?string $cartPredicate = null,
131 ?string $sortOrder = null,
133 ?bool $isActive = null,
134 ?DateTimeImmutable $validFrom = null,
135 ?DateTimeImmutable $validUntil = null,
136 ?bool $requiresDiscountCode = null,
137 ?string $stackingMode = null,
140 ) {
141 $this->name = $name;
142 $this->key = $key;
143 $this->description = $description;
144 $this->value = $value;
145 $this->cartPredicate = $cartPredicate;
146 $this->target = $target;
147 $this->sortOrder = $sortOrder;
148 $this->stores = $stores;
149 $this->isActive = $isActive;
150 $this->validFrom = $validFrom;
151 $this->validUntil = $validUntil;
152 $this->requiresDiscountCode = $requiresDiscountCode;
153 $this->stackingMode = $stackingMode;
154 $this->custom = $custom;
155 $this->discountGroup = $discountGroup;
156 }
157
164 public function getName()
165 {
166 if (is_null($this->name)) {
168 $data = $this->raw(self::FIELD_NAME);
169 if (is_null($data)) {
170 return null;
171 }
172
173 $this->name = LocalizedStringModel::of($data);
174 }
175
176 return $this->name;
177 }
178
185 public function getKey()
186 {
187 if (is_null($this->key)) {
189 $data = $this->raw(self::FIELD_KEY);
190 if (is_null($data)) {
191 return null;
192 }
193 $this->key = (string) $data;
194 }
195
196 return $this->key;
197 }
198
205 public function getDescription()
206 {
207 if (is_null($this->description)) {
209 $data = $this->raw(self::FIELD_DESCRIPTION);
210 if (is_null($data)) {
211 return null;
212 }
213
214 $this->description = LocalizedStringModel::of($data);
215 }
216
217 return $this->description;
218 }
219
226 public function getValue()
227 {
228 if (is_null($this->value)) {
230 $data = $this->raw(self::FIELD_VALUE);
231 if (is_null($data)) {
232 return null;
233 }
235 $this->value = $className::of($data);
236 }
237
238 return $this->value;
239 }
240
247 public function getCartPredicate()
248 {
249 if (is_null($this->cartPredicate)) {
251 $data = $this->raw(self::FIELD_CART_PREDICATE);
252 if (is_null($data)) {
253 return null;
254 }
255 $this->cartPredicate = (string) $data;
256 }
257
259 }
260
268 public function getTarget()
269 {
270 if (is_null($this->target)) {
272 $data = $this->raw(self::FIELD_TARGET);
273 if (is_null($data)) {
274 return null;
275 }
277 $this->target = $className::of($data);
278 }
279
280 return $this->target;
281 }
282
291 public function getSortOrder()
292 {
293 if (is_null($this->sortOrder)) {
295 $data = $this->raw(self::FIELD_SORT_ORDER);
296 if (is_null($data)) {
297 return null;
298 }
299 $this->sortOrder = (string) $data;
300 }
301
302 return $this->sortOrder;
303 }
304
316 public function getStores()
317 {
318 if (is_null($this->stores)) {
320 $data = $this->raw(self::FIELD_STORES);
321 if (is_null($data)) {
322 return null;
323 }
324 $this->stores = StoreResourceIdentifierCollection::fromArray($data);
325 }
326
327 return $this->stores;
328 }
329
337 public function getIsActive()
338 {
339 if (is_null($this->isActive)) {
341 $data = $this->raw(self::FIELD_IS_ACTIVE);
342 if (is_null($data)) {
343 return null;
344 }
345 $this->isActive = (bool) $data;
346 }
347
348 return $this->isActive;
349 }
350
357 public function getValidFrom()
358 {
359 if (is_null($this->validFrom)) {
361 $data = $this->raw(self::FIELD_VALID_FROM);
362 if (is_null($data)) {
363 return null;
364 }
365 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
366 if (false === $data) {
367 return null;
368 }
369 $this->validFrom = $data;
370 }
371
372 return $this->validFrom;
373 }
374
381 public function getValidUntil()
382 {
383 if (is_null($this->validUntil)) {
385 $data = $this->raw(self::FIELD_VALID_UNTIL);
386 if (is_null($data)) {
387 return null;
388 }
389 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
390 if (false === $data) {
391 return null;
392 }
393 $this->validUntil = $data;
394 }
395
396 return $this->validUntil;
397 }
398
405 public function getRequiresDiscountCode()
406 {
407 if (is_null($this->requiresDiscountCode)) {
409 $data = $this->raw(self::FIELD_REQUIRES_DISCOUNT_CODE);
410 if (is_null($data)) {
411 return null;
412 }
413 $this->requiresDiscountCode = (bool) $data;
414 }
415
417 }
418
425 public function getStackingMode()
426 {
427 if (is_null($this->stackingMode)) {
429 $data = $this->raw(self::FIELD_STACKING_MODE);
430 if (is_null($data)) {
431 return null;
432 }
433 $this->stackingMode = (string) $data;
434 }
435
436 return $this->stackingMode;
437 }
438
445 public function getCustom()
446 {
447 if (is_null($this->custom)) {
449 $data = $this->raw(self::FIELD_CUSTOM);
450 if (is_null($data)) {
451 return null;
452 }
453
454 $this->custom = CustomFieldsDraftModel::of($data);
455 }
456
457 return $this->custom;
458 }
459
466 public function getDiscountGroup()
467 {
468 if (is_null($this->discountGroup)) {
470 $data = $this->raw(self::FIELD_DISCOUNT_GROUP);
471 if (is_null($data)) {
472 return null;
473 }
474
475 $this->discountGroup = DiscountGroupResourceIdentifierModel::of($data);
476 }
477
479 }
480
481
485 public function setName(?LocalizedString $name): void
486 {
487 $this->name = $name;
488 }
489
493 public function setKey(?string $key): void
494 {
495 $this->key = $key;
496 }
497
502 {
503 $this->description = $description;
504 }
505
509 public function setValue(?CartDiscountValueDraft $value): void
510 {
511 $this->value = $value;
512 }
513
517 public function setCartPredicate(?string $cartPredicate): void
518 {
519 $this->cartPredicate = $cartPredicate;
520 }
521
525 public function setTarget(?CartDiscountTarget $target): void
526 {
527 $this->target = $target;
528 }
529
533 public function setSortOrder(?string $sortOrder): void
534 {
535 $this->sortOrder = $sortOrder;
536 }
537
542 {
543 $this->stores = $stores;
544 }
545
549 public function setIsActive(?bool $isActive): void
550 {
551 $this->isActive = $isActive;
552 }
553
557 public function setValidFrom(?DateTimeImmutable $validFrom): void
558 {
559 $this->validFrom = $validFrom;
560 }
561
565 public function setValidUntil(?DateTimeImmutable $validUntil): void
566 {
567 $this->validUntil = $validUntil;
568 }
569
574 {
575 $this->requiresDiscountCode = $requiresDiscountCode;
576 }
577
581 public function setStackingMode(?string $stackingMode): void
582 {
583 $this->stackingMode = $stackingMode;
584 }
585
589 public function setCustom(?CustomFieldsDraft $custom): void
590 {
591 $this->custom = $custom;
592 }
593
598 {
599 $this->discountGroup = $discountGroup;
600 }
601
602
603 #[\ReturnTypeWillChange]
604 public function jsonSerialize()
605 {
606 $data = $this->toArray();
607 if (isset($data[CartDiscountDraft::FIELD_VALID_FROM]) && $data[CartDiscountDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
608 $data[CartDiscountDraft::FIELD_VALID_FROM] = $data[CartDiscountDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
609 }
610
611 if (isset($data[CartDiscountDraft::FIELD_VALID_UNTIL]) && $data[CartDiscountDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
612 $data[CartDiscountDraft::FIELD_VALID_UNTIL] = $data[CartDiscountDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
613 }
614 return (object) $data;
615 }
616}
__construct(?LocalizedString $name=null, ?string $key=null, ?LocalizedString $description=null, ?CartDiscountValueDraft $value=null, ?string $cartPredicate=null, ?CartDiscountTarget $target=null, ?string $sortOrder=null, ?StoreResourceIdentifierCollection $stores=null, ?bool $isActive=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?bool $requiresDiscountCode=null, ?string $stackingMode=null, ?CustomFieldsDraft $custom=null, ?DiscountGroupResourceIdentifier $discountGroup=null)
setDiscountGroup(?DiscountGroupResourceIdentifier $discountGroup)