commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
StandalonePriceDraftModel.php
1<?php
2
3declare(strict_types=1);
10
28use DateTimeImmutable;
29use stdClass;
30
35{
40 protected $key;
41
46 protected $sku;
47
52 protected $value;
53
58 protected $country;
59
64 protected $customerGroup;
65
70 protected $channel;
71
76 protected $validFrom;
77
82 protected $validUntil;
83
88 protected $tiers;
89
94 protected $discounted;
95
100 protected $custom;
101
107
112 protected $staged;
113
118 protected $active;
119
120
124 public function __construct(
125 ?string $key = null,
126 ?string $sku = null,
127 ?Money $value = null,
128 ?string $country = null,
131 ?DateTimeImmutable $validFrom = null,
132 ?DateTimeImmutable $validUntil = null,
138 ?bool $active = null
139 ) {
140 $this->key = $key;
141 $this->sku = $sku;
142 $this->value = $value;
143 $this->country = $country;
144 $this->customerGroup = $customerGroup;
145 $this->channel = $channel;
146 $this->validFrom = $validFrom;
147 $this->validUntil = $validUntil;
148 $this->tiers = $tiers;
149 $this->discounted = $discounted;
150 $this->custom = $custom;
151 $this->recurrencePolicy = $recurrencePolicy;
152 $this->staged = $staged;
153 $this->active = $active;
154 }
155
163 public function getKey()
164 {
165 if (is_null($this->key)) {
167 $data = $this->raw(self::FIELD_KEY);
168 if (is_null($data)) {
169 return null;
170 }
171 $this->key = (string) $data;
172 }
173
174 return $this->key;
175 }
176
184 public function getSku()
185 {
186 if (is_null($this->sku)) {
188 $data = $this->raw(self::FIELD_SKU);
189 if (is_null($data)) {
190 return null;
191 }
192 $this->sku = (string) $data;
193 }
194
195 return $this->sku;
196 }
197
205 public function getValue()
206 {
207 if (is_null($this->value)) {
209 $data = $this->raw(self::FIELD_VALUE);
210 if (is_null($data)) {
211 return null;
212 }
213
214 $this->value = MoneyModel::of($data);
215 }
216
217 return $this->value;
218 }
219
226 public function getCountry()
227 {
228 if (is_null($this->country)) {
230 $data = $this->raw(self::FIELD_COUNTRY);
231 if (is_null($data)) {
232 return null;
233 }
234 $this->country = (string) $data;
235 }
236
237 return $this->country;
238 }
239
246 public function getCustomerGroup()
247 {
248 if (is_null($this->customerGroup)) {
250 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
251 if (is_null($data)) {
252 return null;
253 }
254
255 $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
256 }
257
259 }
260
268 public function getChannel()
269 {
270 if (is_null($this->channel)) {
272 $data = $this->raw(self::FIELD_CHANNEL);
273 if (is_null($data)) {
274 return null;
275 }
276
277 $this->channel = ChannelResourceIdentifierModel::of($data);
278 }
279
280 return $this->channel;
281 }
282
289 public function getValidFrom()
290 {
291 if (is_null($this->validFrom)) {
293 $data = $this->raw(self::FIELD_VALID_FROM);
294 if (is_null($data)) {
295 return null;
296 }
297 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
298 if (false === $data) {
299 return null;
300 }
301 $this->validFrom = $data;
302 }
303
304 return $this->validFrom;
305 }
306
313 public function getValidUntil()
314 {
315 if (is_null($this->validUntil)) {
317 $data = $this->raw(self::FIELD_VALID_UNTIL);
318 if (is_null($data)) {
319 return null;
320 }
321 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
322 if (false === $data) {
323 return null;
324 }
325 $this->validUntil = $data;
326 }
327
328 return $this->validUntil;
329 }
330
338 public function getTiers()
339 {
340 if (is_null($this->tiers)) {
342 $data = $this->raw(self::FIELD_TIERS);
343 if (is_null($data)) {
344 return null;
345 }
346 $this->tiers = PriceTierDraftCollection::fromArray($data);
347 }
348
349 return $this->tiers;
350 }
351
358 public function getDiscounted()
359 {
360 if (is_null($this->discounted)) {
362 $data = $this->raw(self::FIELD_DISCOUNTED);
363 if (is_null($data)) {
364 return null;
365 }
366
367 $this->discounted = DiscountedPriceDraftModel::of($data);
368 }
369
370 return $this->discounted;
371 }
372
379 public function getCustom()
380 {
381 if (is_null($this->custom)) {
383 $data = $this->raw(self::FIELD_CUSTOM);
384 if (is_null($data)) {
385 return null;
386 }
387
388 $this->custom = CustomFieldsDraftModel::of($data);
389 }
390
391 return $this->custom;
392 }
393
400 public function getRecurrencePolicy()
401 {
402 if (is_null($this->recurrencePolicy)) {
404 $data = $this->raw(self::FIELD_RECURRENCE_POLICY);
405 if (is_null($data)) {
406 return null;
407 }
408
409 $this->recurrencePolicy = RecurrencePolicyResourceIdentifierModel::of($data);
410 }
411
413 }
414
421 public function getStaged()
422 {
423 if (is_null($this->staged)) {
425 $data = $this->raw(self::FIELD_STAGED);
426 if (is_null($data)) {
427 return null;
428 }
429
430 $this->staged = StagedPriceDraftModel::of($data);
431 }
432
433 return $this->staged;
434 }
435
442 public function getActive()
443 {
444 if (is_null($this->active)) {
446 $data = $this->raw(self::FIELD_ACTIVE);
447 if (is_null($data)) {
448 return null;
449 }
450 $this->active = (bool) $data;
451 }
452
453 return $this->active;
454 }
455
456
460 public function setKey(?string $key): void
461 {
462 $this->key = $key;
463 }
464
468 public function setSku(?string $sku): void
469 {
470 $this->sku = $sku;
471 }
472
476 public function setValue(?Money $value): void
477 {
478 $this->value = $value;
479 }
480
484 public function setCountry(?string $country): void
485 {
486 $this->country = $country;
487 }
488
493 {
494 $this->customerGroup = $customerGroup;
495 }
496
501 {
502 $this->channel = $channel;
503 }
504
508 public function setValidFrom(?DateTimeImmutable $validFrom): void
509 {
510 $this->validFrom = $validFrom;
511 }
512
516 public function setValidUntil(?DateTimeImmutable $validUntil): void
517 {
518 $this->validUntil = $validUntil;
519 }
520
525 {
526 $this->tiers = $tiers;
527 }
528
533 {
534 $this->discounted = $discounted;
535 }
536
540 public function setCustom(?CustomFieldsDraft $custom): void
541 {
542 $this->custom = $custom;
543 }
544
549 {
550 $this->recurrencePolicy = $recurrencePolicy;
551 }
552
556 public function setStaged(?StagedPriceDraft $staged): void
557 {
558 $this->staged = $staged;
559 }
560
564 public function setActive(?bool $active): void
565 {
566 $this->active = $active;
567 }
568
569
570 #[\ReturnTypeWillChange]
571 public function jsonSerialize()
572 {
573 $data = $this->toArray();
574 if (isset($data[StandalonePriceDraft::FIELD_VALID_FROM]) && $data[StandalonePriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
575 $data[StandalonePriceDraft::FIELD_VALID_FROM] = $data[StandalonePriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
576 }
577
578 if (isset($data[StandalonePriceDraft::FIELD_VALID_UNTIL]) && $data[StandalonePriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
579 $data[StandalonePriceDraft::FIELD_VALID_UNTIL] = $data[StandalonePriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
580 }
581 return (object) $data;
582 }
583}
setRecurrencePolicy(?RecurrencePolicyResourceIdentifier $recurrencePolicy)
__construct(?string $key=null, ?string $sku=null, ?Money $value=null, ?string $country=null, ?CustomerGroupResourceIdentifier $customerGroup=null, ?ChannelResourceIdentifier $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?PriceTierDraftCollection $tiers=null, ?DiscountedPriceDraft $discounted=null, ?CustomFieldsDraft $custom=null, ?RecurrencePolicyResourceIdentifier $recurrencePolicy=null, ?StagedPriceDraft $staged=null, ?bool $active=null)