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
24use DateTimeImmutable;
25use stdClass;
26
31{
36 protected $name;
37
42 protected $key;
43
48 protected $description;
49
54 protected $value;
55
60 protected $cartPredicate;
61
66 protected $target;
67
72 protected $sortOrder;
73
78 protected $stores;
79
84 protected $isActive;
85
90 protected $validFrom;
91
96 protected $validUntil;
97
103
108 protected $stackingMode;
109
114 protected $custom;
115
120 protected $discountGroup;
121
127
128
132 public function __construct(
133 ?LocalizedString $name = null,
134 ?string $key = null,
137 ?string $cartPredicate = null,
139 ?string $sortOrder = null,
141 ?bool $isActive = null,
142 ?DateTimeImmutable $validFrom = null,
143 ?DateTimeImmutable $validUntil = null,
144 ?bool $requiresDiscountCode = null,
145 ?string $stackingMode = null,
149 ) {
150 $this->name = $name;
151 $this->key = $key;
152 $this->description = $description;
153 $this->value = $value;
154 $this->cartPredicate = $cartPredicate;
155 $this->target = $target;
156 $this->sortOrder = $sortOrder;
157 $this->stores = $stores;
158 $this->isActive = $isActive;
159 $this->validFrom = $validFrom;
160 $this->validUntil = $validUntil;
161 $this->requiresDiscountCode = $requiresDiscountCode;
162 $this->stackingMode = $stackingMode;
163 $this->custom = $custom;
164 $this->discountGroup = $discountGroup;
165 $this->recurringOrderScope = $recurringOrderScope;
166 }
167
174 public function getName()
175 {
176 if (is_null($this->name)) {
178 $data = $this->raw(self::FIELD_NAME);
179 if (is_null($data)) {
180 return null;
181 }
182
183 $this->name = LocalizedStringModel::of($data);
184 }
185
186 return $this->name;
187 }
188
195 public function getKey()
196 {
197 if (is_null($this->key)) {
199 $data = $this->raw(self::FIELD_KEY);
200 if (is_null($data)) {
201 return null;
202 }
203 $this->key = (string) $data;
204 }
205
206 return $this->key;
207 }
208
215 public function getDescription()
216 {
217 if (is_null($this->description)) {
219 $data = $this->raw(self::FIELD_DESCRIPTION);
220 if (is_null($data)) {
221 return null;
222 }
223
224 $this->description = LocalizedStringModel::of($data);
225 }
226
227 return $this->description;
228 }
229
236 public function getValue()
237 {
238 if (is_null($this->value)) {
240 $data = $this->raw(self::FIELD_VALUE);
241 if (is_null($data)) {
242 return null;
243 }
245 $this->value = $className::of($data);
246 }
247
248 return $this->value;
249 }
250
257 public function getCartPredicate()
258 {
259 if (is_null($this->cartPredicate)) {
261 $data = $this->raw(self::FIELD_CART_PREDICATE);
262 if (is_null($data)) {
263 return null;
264 }
265 $this->cartPredicate = (string) $data;
266 }
267
269 }
270
278 public function getTarget()
279 {
280 if (is_null($this->target)) {
282 $data = $this->raw(self::FIELD_TARGET);
283 if (is_null($data)) {
284 return null;
285 }
287 $this->target = $className::of($data);
288 }
289
290 return $this->target;
291 }
292
301 public function getSortOrder()
302 {
303 if (is_null($this->sortOrder)) {
305 $data = $this->raw(self::FIELD_SORT_ORDER);
306 if (is_null($data)) {
307 return null;
308 }
309 $this->sortOrder = (string) $data;
310 }
311
312 return $this->sortOrder;
313 }
314
326 public function getStores()
327 {
328 if (is_null($this->stores)) {
330 $data = $this->raw(self::FIELD_STORES);
331 if (is_null($data)) {
332 return null;
333 }
334 $this->stores = StoreResourceIdentifierCollection::fromArray($data);
335 }
336
337 return $this->stores;
338 }
339
347 public function getIsActive()
348 {
349 if (is_null($this->isActive)) {
351 $data = $this->raw(self::FIELD_IS_ACTIVE);
352 if (is_null($data)) {
353 return null;
354 }
355 $this->isActive = (bool) $data;
356 }
357
358 return $this->isActive;
359 }
360
367 public function getValidFrom()
368 {
369 if (is_null($this->validFrom)) {
371 $data = $this->raw(self::FIELD_VALID_FROM);
372 if (is_null($data)) {
373 return null;
374 }
375 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
376 if (false === $data) {
377 return null;
378 }
379 $this->validFrom = $data;
380 }
381
382 return $this->validFrom;
383 }
384
391 public function getValidUntil()
392 {
393 if (is_null($this->validUntil)) {
395 $data = $this->raw(self::FIELD_VALID_UNTIL);
396 if (is_null($data)) {
397 return null;
398 }
399 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
400 if (false === $data) {
401 return null;
402 }
403 $this->validUntil = $data;
404 }
405
406 return $this->validUntil;
407 }
408
415 public function getRequiresDiscountCode()
416 {
417 if (is_null($this->requiresDiscountCode)) {
419 $data = $this->raw(self::FIELD_REQUIRES_DISCOUNT_CODE);
420 if (is_null($data)) {
421 return null;
422 }
423 $this->requiresDiscountCode = (bool) $data;
424 }
425
427 }
428
435 public function getStackingMode()
436 {
437 if (is_null($this->stackingMode)) {
439 $data = $this->raw(self::FIELD_STACKING_MODE);
440 if (is_null($data)) {
441 return null;
442 }
443 $this->stackingMode = (string) $data;
444 }
445
446 return $this->stackingMode;
447 }
448
455 public function getCustom()
456 {
457 if (is_null($this->custom)) {
459 $data = $this->raw(self::FIELD_CUSTOM);
460 if (is_null($data)) {
461 return null;
462 }
463
464 $this->custom = CustomFieldsDraftModel::of($data);
465 }
466
467 return $this->custom;
468 }
469
476 public function getDiscountGroup()
477 {
478 if (is_null($this->discountGroup)) {
480 $data = $this->raw(self::FIELD_DISCOUNT_GROUP);
481 if (is_null($data)) {
482 return null;
483 }
484
485 $this->discountGroup = DiscountGroupResourceIdentifierModel::of($data);
486 }
487
489 }
490
498 public function getRecurringOrderScope()
499 {
500 if (is_null($this->recurringOrderScope)) {
502 $data = $this->raw(self::FIELD_RECURRING_ORDER_SCOPE);
503 if (is_null($data)) {
504 return null;
505 }
506 $className = RecurringOrderScopeDraftModel::resolveDiscriminatorClass($data);
507 $this->recurringOrderScope = $className::of($data);
508 }
509
511 }
512
513
517 public function setName(?LocalizedString $name): void
518 {
519 $this->name = $name;
520 }
521
525 public function setKey(?string $key): void
526 {
527 $this->key = $key;
528 }
529
534 {
535 $this->description = $description;
536 }
537
541 public function setValue(?CartDiscountValueDraft $value): void
542 {
543 $this->value = $value;
544 }
545
549 public function setCartPredicate(?string $cartPredicate): void
550 {
551 $this->cartPredicate = $cartPredicate;
552 }
553
557 public function setTarget(?CartDiscountTarget $target): void
558 {
559 $this->target = $target;
560 }
561
565 public function setSortOrder(?string $sortOrder): void
566 {
567 $this->sortOrder = $sortOrder;
568 }
569
574 {
575 $this->stores = $stores;
576 }
577
581 public function setIsActive(?bool $isActive): void
582 {
583 $this->isActive = $isActive;
584 }
585
589 public function setValidFrom(?DateTimeImmutable $validFrom): void
590 {
591 $this->validFrom = $validFrom;
592 }
593
597 public function setValidUntil(?DateTimeImmutable $validUntil): void
598 {
599 $this->validUntil = $validUntil;
600 }
601
606 {
607 $this->requiresDiscountCode = $requiresDiscountCode;
608 }
609
613 public function setStackingMode(?string $stackingMode): void
614 {
615 $this->stackingMode = $stackingMode;
616 }
617
621 public function setCustom(?CustomFieldsDraft $custom): void
622 {
623 $this->custom = $custom;
624 }
625
630 {
631 $this->discountGroup = $discountGroup;
632 }
633
638 {
639 $this->recurringOrderScope = $recurringOrderScope;
640 }
641
642
643 #[\ReturnTypeWillChange]
644 public function jsonSerialize()
645 {
646 $data = $this->toArray();
647 if (isset($data[CartDiscountDraft::FIELD_VALID_FROM]) && $data[CartDiscountDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
648 $data[CartDiscountDraft::FIELD_VALID_FROM] = $data[CartDiscountDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
649 }
650
651 if (isset($data[CartDiscountDraft::FIELD_VALID_UNTIL]) && $data[CartDiscountDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
652 $data[CartDiscountDraft::FIELD_VALID_UNTIL] = $data[CartDiscountDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
653 }
654 return (object) $data;
655 }
656}
setRecurringOrderScope(?RecurringOrderScopeDraft $recurringOrderScope)
__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, ?RecurringOrderScopeDraft $recurringOrderScope=null)
setDiscountGroup(?DiscountGroupResourceIdentifier $discountGroup)