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
196 public function getKey()
197 {
198 if (is_null($this->key)) {
200 $data = $this->raw(self::FIELD_KEY);
201 if (is_null($data)) {
202 return null;
203 }
204 $this->key = (string) $data;
205 }
206
207 return $this->key;
208 }
209
216 public function getDescription()
217 {
218 if (is_null($this->description)) {
220 $data = $this->raw(self::FIELD_DESCRIPTION);
221 if (is_null($data)) {
222 return null;
223 }
224
225 $this->description = LocalizedStringModel::of($data);
226 }
227
228 return $this->description;
229 }
230
237 public function getValue()
238 {
239 if (is_null($this->value)) {
241 $data = $this->raw(self::FIELD_VALUE);
242 if (is_null($data)) {
243 return null;
244 }
246 $this->value = $className::of($data);
247 }
248
249 return $this->value;
250 }
251
258 public function getCartPredicate()
259 {
260 if (is_null($this->cartPredicate)) {
262 $data = $this->raw(self::FIELD_CART_PREDICATE);
263 if (is_null($data)) {
264 return null;
265 }
266 $this->cartPredicate = (string) $data;
267 }
268
270 }
271
279 public function getTarget()
280 {
281 if (is_null($this->target)) {
283 $data = $this->raw(self::FIELD_TARGET);
284 if (is_null($data)) {
285 return null;
286 }
288 $this->target = $className::of($data);
289 }
290
291 return $this->target;
292 }
293
302 public function getSortOrder()
303 {
304 if (is_null($this->sortOrder)) {
306 $data = $this->raw(self::FIELD_SORT_ORDER);
307 if (is_null($data)) {
308 return null;
309 }
310 $this->sortOrder = (string) $data;
311 }
312
313 return $this->sortOrder;
314 }
315
327 public function getStores()
328 {
329 if (is_null($this->stores)) {
331 $data = $this->raw(self::FIELD_STORES);
332 if (is_null($data)) {
333 return null;
334 }
335 $this->stores = StoreResourceIdentifierCollection::fromArray($data);
336 }
337
338 return $this->stores;
339 }
340
348 public function getIsActive()
349 {
350 if (is_null($this->isActive)) {
352 $data = $this->raw(self::FIELD_IS_ACTIVE);
353 if (is_null($data)) {
354 return null;
355 }
356 $this->isActive = (bool) $data;
357 }
358
359 return $this->isActive;
360 }
361
368 public function getValidFrom()
369 {
370 if (is_null($this->validFrom)) {
372 $data = $this->raw(self::FIELD_VALID_FROM);
373 if (is_null($data)) {
374 return null;
375 }
376 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
377 if (false === $data) {
378 return null;
379 }
380 $this->validFrom = $data;
381 }
382
383 return $this->validFrom;
384 }
385
392 public function getValidUntil()
393 {
394 if (is_null($this->validUntil)) {
396 $data = $this->raw(self::FIELD_VALID_UNTIL);
397 if (is_null($data)) {
398 return null;
399 }
400 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
401 if (false === $data) {
402 return null;
403 }
404 $this->validUntil = $data;
405 }
406
407 return $this->validUntil;
408 }
409
416 public function getRequiresDiscountCode()
417 {
418 if (is_null($this->requiresDiscountCode)) {
420 $data = $this->raw(self::FIELD_REQUIRES_DISCOUNT_CODE);
421 if (is_null($data)) {
422 return null;
423 }
424 $this->requiresDiscountCode = (bool) $data;
425 }
426
428 }
429
436 public function getStackingMode()
437 {
438 if (is_null($this->stackingMode)) {
440 $data = $this->raw(self::FIELD_STACKING_MODE);
441 if (is_null($data)) {
442 return null;
443 }
444 $this->stackingMode = (string) $data;
445 }
446
447 return $this->stackingMode;
448 }
449
456 public function getCustom()
457 {
458 if (is_null($this->custom)) {
460 $data = $this->raw(self::FIELD_CUSTOM);
461 if (is_null($data)) {
462 return null;
463 }
464
465 $this->custom = CustomFieldsDraftModel::of($data);
466 }
467
468 return $this->custom;
469 }
470
478 public function getDiscountGroup()
479 {
480 if (is_null($this->discountGroup)) {
482 $data = $this->raw(self::FIELD_DISCOUNT_GROUP);
483 if (is_null($data)) {
484 return null;
485 }
486
487 $this->discountGroup = DiscountGroupResourceIdentifierModel::of($data);
488 }
489
491 }
492
500 public function getRecurringOrderScope()
501 {
502 if (is_null($this->recurringOrderScope)) {
504 $data = $this->raw(self::FIELD_RECURRING_ORDER_SCOPE);
505 if (is_null($data)) {
506 return null;
507 }
508 $className = RecurringOrderScopeDraftModel::resolveDiscriminatorClass($data);
509 $this->recurringOrderScope = $className::of($data);
510 }
511
513 }
514
515
519 public function setName(?LocalizedString $name): void
520 {
521 $this->name = $name;
522 }
523
527 public function setKey(?string $key): void
528 {
529 $this->key = $key;
530 }
531
536 {
537 $this->description = $description;
538 }
539
543 public function setValue(?CartDiscountValueDraft $value): void
544 {
545 $this->value = $value;
546 }
547
551 public function setCartPredicate(?string $cartPredicate): void
552 {
553 $this->cartPredicate = $cartPredicate;
554 }
555
559 public function setTarget(?CartDiscountTarget $target): void
560 {
561 $this->target = $target;
562 }
563
567 public function setSortOrder(?string $sortOrder): void
568 {
569 $this->sortOrder = $sortOrder;
570 }
571
576 {
577 $this->stores = $stores;
578 }
579
583 public function setIsActive(?bool $isActive): void
584 {
585 $this->isActive = $isActive;
586 }
587
591 public function setValidFrom(?DateTimeImmutable $validFrom): void
592 {
593 $this->validFrom = $validFrom;
594 }
595
599 public function setValidUntil(?DateTimeImmutable $validUntil): void
600 {
601 $this->validUntil = $validUntil;
602 }
603
608 {
609 $this->requiresDiscountCode = $requiresDiscountCode;
610 }
611
615 public function setStackingMode(?string $stackingMode): void
616 {
617 $this->stackingMode = $stackingMode;
618 }
619
623 public function setCustom(?CustomFieldsDraft $custom): void
624 {
625 $this->custom = $custom;
626 }
627
632 {
633 $this->discountGroup = $discountGroup;
634 }
635
640 {
641 $this->recurringOrderScope = $recurringOrderScope;
642 }
643
644
645 #[\ReturnTypeWillChange]
646 public function jsonSerialize()
647 {
648 $data = $this->toArray();
649 if (isset($data[CartDiscountDraft::FIELD_VALID_FROM]) && $data[CartDiscountDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
650 $data[CartDiscountDraft::FIELD_VALID_FROM] = $data[CartDiscountDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
651 }
652
653 if (isset($data[CartDiscountDraft::FIELD_VALID_UNTIL]) && $data[CartDiscountDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
654 $data[CartDiscountDraft::FIELD_VALID_UNTIL] = $data[CartDiscountDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
655 }
656 return (object) $data;
657 }
658}
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)