commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
DiscountCodeImportModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
22 use DateTimeImmutable;
23 use 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 
76  protected $maxApplications;
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 
211  public function getCode()
212  {
213  if (is_null($this->code)) {
215  $data = $this->raw(self::FIELD_CODE);
216  if (is_null($data)) {
217  return null;
218  }
219  $this->code = (string) $data;
220  }
221 
222  return $this->code;
223  }
224 
231  public function getCartDiscounts()
232  {
233  if (is_null($this->cartDiscounts)) {
235  $data = $this->raw(self::FIELD_CART_DISCOUNTS);
236  if (is_null($data)) {
237  return null;
238  }
239  $this->cartDiscounts = CartDiscountKeyReferenceCollection::fromArray($data);
240  }
241 
242  return $this->cartDiscounts;
243  }
244 
251  public function getCartPredicate()
252  {
253  if (is_null($this->cartPredicate)) {
255  $data = $this->raw(self::FIELD_CART_PREDICATE);
256  if (is_null($data)) {
257  return null;
258  }
259  $this->cartPredicate = (string) $data;
260  }
261 
262  return $this->cartPredicate;
263  }
264 
271  public function getIsActive()
272  {
273  if (is_null($this->isActive)) {
275  $data = $this->raw(self::FIELD_IS_ACTIVE);
276  if (is_null($data)) {
277  return null;
278  }
279  $this->isActive = (bool) $data;
280  }
281 
282  return $this->isActive;
283  }
284 
291  public function getMaxApplications()
292  {
293  if (is_null($this->maxApplications)) {
295  $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
296  if (is_null($data)) {
297  return null;
298  }
299  $this->maxApplications = (int) $data;
300  }
301 
302  return $this->maxApplications;
303  }
304 
312  {
313  if (is_null($this->maxApplicationsPerCustomer)) {
315  $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
316  if (is_null($data)) {
317  return null;
318  }
319  $this->maxApplicationsPerCustomer = (int) $data;
320  }
321 
323  }
324 
331  public function getGroups()
332  {
333  if (is_null($this->groups)) {
335  $data = $this->raw(self::FIELD_GROUPS);
336  if (is_null($data)) {
337  return null;
338  }
339  $this->groups = $data;
340  }
341 
342  return $this->groups;
343  }
344 
351  public function getValidFrom()
352  {
353  if (is_null($this->validFrom)) {
355  $data = $this->raw(self::FIELD_VALID_FROM);
356  if (is_null($data)) {
357  return null;
358  }
359  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
360  if (false === $data) {
361  return null;
362  }
363  $this->validFrom = $data;
364  }
365 
366  return $this->validFrom;
367  }
368 
375  public function getValidUntil()
376  {
377  if (is_null($this->validUntil)) {
379  $data = $this->raw(self::FIELD_VALID_UNTIL);
380  if (is_null($data)) {
381  return null;
382  }
383  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
384  if (false === $data) {
385  return null;
386  }
387  $this->validUntil = $data;
388  }
389 
390  return $this->validUntil;
391  }
392 
399  public function getCustom()
400  {
401  if (is_null($this->custom)) {
403  $data = $this->raw(self::FIELD_CUSTOM);
404  if (is_null($data)) {
405  return null;
406  }
407 
408  $this->custom = CustomModel::of($data);
409  }
410 
411  return $this->custom;
412  }
413 
414 
418  public function setKey(?string $key): void
419  {
420  $this->key = $key;
421  }
422 
426  public function setName(?LocalizedString $name): void
427  {
428  $this->name = $name;
429  }
430 
435  {
436  $this->description = $description;
437  }
438 
442  public function setCode(?string $code): void
443  {
444  $this->code = $code;
445  }
446 
451  {
452  $this->cartDiscounts = $cartDiscounts;
453  }
454 
458  public function setCartPredicate(?string $cartPredicate): void
459  {
460  $this->cartPredicate = $cartPredicate;
461  }
462 
466  public function setIsActive(?bool $isActive): void
467  {
468  $this->isActive = $isActive;
469  }
470 
474  public function setMaxApplications(?int $maxApplications): void
475  {
476  $this->maxApplications = $maxApplications;
477  }
478 
483  {
484  $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
485  }
486 
490  public function setGroups(?array $groups): void
491  {
492  $this->groups = $groups;
493  }
494 
498  public function setValidFrom(?DateTimeImmutable $validFrom): void
499  {
500  $this->validFrom = $validFrom;
501  }
502 
506  public function setValidUntil(?DateTimeImmutable $validUntil): void
507  {
508  $this->validUntil = $validUntil;
509  }
510 
514  public function setCustom(?Custom $custom): void
515  {
516  $this->custom = $custom;
517  }
518 
519 
520  #[\ReturnTypeWillChange]
521  public function jsonSerialize()
522  {
523  $data = $this->toArray();
524  if (isset($data[DiscountCodeImport::FIELD_VALID_FROM]) && $data[DiscountCodeImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
525  $data[DiscountCodeImport::FIELD_VALID_FROM] = $data[DiscountCodeImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
526  }
527 
528  if (isset($data[DiscountCodeImport::FIELD_VALID_UNTIL]) && $data[DiscountCodeImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
529  $data[DiscountCodeImport::FIELD_VALID_UNTIL] = $data[DiscountCodeImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
530  }
531  return (object) $data;
532  }
533 }
static of($data=null)
Definition: MapperMap.php:45
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)