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
20use DateTimeImmutable;
21use stdClass;
22
27{
32 protected $name;
33
38 protected $key;
39
44 protected $description;
45
50 protected $value;
51
56 protected $cartPredicate;
57
62 protected $target;
63
68 protected $sortOrder;
69
74 protected $stores;
75
80 protected $isActive;
81
86 protected $validFrom;
87
92 protected $validUntil;
93
99
104 protected $stackingMode;
105
110 protected $custom;
111
112
116 public function __construct(
117 ?LocalizedString $name = null,
118 ?string $key = null,
121 ?string $cartPredicate = null,
123 ?string $sortOrder = null,
125 ?bool $isActive = null,
126 ?DateTimeImmutable $validFrom = null,
127 ?DateTimeImmutable $validUntil = null,
128 ?bool $requiresDiscountCode = null,
129 ?string $stackingMode = null,
131 ) {
132 $this->name = $name;
133 $this->key = $key;
134 $this->description = $description;
135 $this->value = $value;
136 $this->cartPredicate = $cartPredicate;
137 $this->target = $target;
138 $this->sortOrder = $sortOrder;
139 $this->stores = $stores;
140 $this->isActive = $isActive;
141 $this->validFrom = $validFrom;
142 $this->validUntil = $validUntil;
143 $this->requiresDiscountCode = $requiresDiscountCode;
144 $this->stackingMode = $stackingMode;
145 $this->custom = $custom;
146 }
147
154 public function getName()
155 {
156 if (is_null($this->name)) {
158 $data = $this->raw(self::FIELD_NAME);
159 if (is_null($data)) {
160 return null;
161 }
162
163 $this->name = LocalizedStringModel::of($data);
164 }
165
166 return $this->name;
167 }
168
175 public function getKey()
176 {
177 if (is_null($this->key)) {
179 $data = $this->raw(self::FIELD_KEY);
180 if (is_null($data)) {
181 return null;
182 }
183 $this->key = (string) $data;
184 }
185
186 return $this->key;
187 }
188
195 public function getDescription()
196 {
197 if (is_null($this->description)) {
199 $data = $this->raw(self::FIELD_DESCRIPTION);
200 if (is_null($data)) {
201 return null;
202 }
203
204 $this->description = LocalizedStringModel::of($data);
205 }
206
207 return $this->description;
208 }
209
216 public function getValue()
217 {
218 if (is_null($this->value)) {
220 $data = $this->raw(self::FIELD_VALUE);
221 if (is_null($data)) {
222 return null;
223 }
225 $this->value = $className::of($data);
226 }
227
228 return $this->value;
229 }
230
237 public function getCartPredicate()
238 {
239 if (is_null($this->cartPredicate)) {
241 $data = $this->raw(self::FIELD_CART_PREDICATE);
242 if (is_null($data)) {
243 return null;
244 }
245 $this->cartPredicate = (string) $data;
246 }
247
249 }
250
258 public function getTarget()
259 {
260 if (is_null($this->target)) {
262 $data = $this->raw(self::FIELD_TARGET);
263 if (is_null($data)) {
264 return null;
265 }
267 $this->target = $className::of($data);
268 }
269
270 return $this->target;
271 }
272
281 public function getSortOrder()
282 {
283 if (is_null($this->sortOrder)) {
285 $data = $this->raw(self::FIELD_SORT_ORDER);
286 if (is_null($data)) {
287 return null;
288 }
289 $this->sortOrder = (string) $data;
290 }
291
292 return $this->sortOrder;
293 }
294
306 public function getStores()
307 {
308 if (is_null($this->stores)) {
310 $data = $this->raw(self::FIELD_STORES);
311 if (is_null($data)) {
312 return null;
313 }
314 $this->stores = StoreResourceIdentifierCollection::fromArray($data);
315 }
316
317 return $this->stores;
318 }
319
327 public function getIsActive()
328 {
329 if (is_null($this->isActive)) {
331 $data = $this->raw(self::FIELD_IS_ACTIVE);
332 if (is_null($data)) {
333 return null;
334 }
335 $this->isActive = (bool) $data;
336 }
337
338 return $this->isActive;
339 }
340
347 public function getValidFrom()
348 {
349 if (is_null($this->validFrom)) {
351 $data = $this->raw(self::FIELD_VALID_FROM);
352 if (is_null($data)) {
353 return null;
354 }
355 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
356 if (false === $data) {
357 return null;
358 }
359 $this->validFrom = $data;
360 }
361
362 return $this->validFrom;
363 }
364
371 public function getValidUntil()
372 {
373 if (is_null($this->validUntil)) {
375 $data = $this->raw(self::FIELD_VALID_UNTIL);
376 if (is_null($data)) {
377 return null;
378 }
379 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
380 if (false === $data) {
381 return null;
382 }
383 $this->validUntil = $data;
384 }
385
386 return $this->validUntil;
387 }
388
395 public function getRequiresDiscountCode()
396 {
397 if (is_null($this->requiresDiscountCode)) {
399 $data = $this->raw(self::FIELD_REQUIRES_DISCOUNT_CODE);
400 if (is_null($data)) {
401 return null;
402 }
403 $this->requiresDiscountCode = (bool) $data;
404 }
405
407 }
408
415 public function getStackingMode()
416 {
417 if (is_null($this->stackingMode)) {
419 $data = $this->raw(self::FIELD_STACKING_MODE);
420 if (is_null($data)) {
421 return null;
422 }
423 $this->stackingMode = (string) $data;
424 }
425
426 return $this->stackingMode;
427 }
428
435 public function getCustom()
436 {
437 if (is_null($this->custom)) {
439 $data = $this->raw(self::FIELD_CUSTOM);
440 if (is_null($data)) {
441 return null;
442 }
443
444 $this->custom = CustomFieldsDraftModel::of($data);
445 }
446
447 return $this->custom;
448 }
449
450
454 public function setName(?LocalizedString $name): void
455 {
456 $this->name = $name;
457 }
458
462 public function setKey(?string $key): void
463 {
464 $this->key = $key;
465 }
466
471 {
472 $this->description = $description;
473 }
474
478 public function setValue(?CartDiscountValueDraft $value): void
479 {
480 $this->value = $value;
481 }
482
486 public function setCartPredicate(?string $cartPredicate): void
487 {
488 $this->cartPredicate = $cartPredicate;
489 }
490
494 public function setTarget(?CartDiscountTarget $target): void
495 {
496 $this->target = $target;
497 }
498
502 public function setSortOrder(?string $sortOrder): void
503 {
504 $this->sortOrder = $sortOrder;
505 }
506
511 {
512 $this->stores = $stores;
513 }
514
518 public function setIsActive(?bool $isActive): void
519 {
520 $this->isActive = $isActive;
521 }
522
526 public function setValidFrom(?DateTimeImmutable $validFrom): void
527 {
528 $this->validFrom = $validFrom;
529 }
530
534 public function setValidUntil(?DateTimeImmutable $validUntil): void
535 {
536 $this->validUntil = $validUntil;
537 }
538
543 {
544 $this->requiresDiscountCode = $requiresDiscountCode;
545 }
546
550 public function setStackingMode(?string $stackingMode): void
551 {
552 $this->stackingMode = $stackingMode;
553 }
554
558 public function setCustom(?CustomFieldsDraft $custom): void
559 {
560 $this->custom = $custom;
561 }
562
563
564 #[\ReturnTypeWillChange]
565 public function jsonSerialize()
566 {
567 $data = $this->toArray();
568 if (isset($data[CartDiscountDraft::FIELD_VALID_FROM]) && $data[CartDiscountDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
569 $data[CartDiscountDraft::FIELD_VALID_FROM] = $data[CartDiscountDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
570 }
571
572 if (isset($data[CartDiscountDraft::FIELD_VALID_UNTIL]) && $data[CartDiscountDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
573 $data[CartDiscountDraft::FIELD_VALID_UNTIL] = $data[CartDiscountDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
574 }
575 return (object) $data;
576 }
577}
__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)