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
162 public function getKey()
163 {
164 if (is_null($this->key)) {
166 $data = $this->raw(self::FIELD_KEY);
167 if (is_null($data)) {
168 return null;
169 }
170 $this->key = (string) $data;
171 }
172
173 return $this->key;
174 }
175
183 public function getSku()
184 {
185 if (is_null($this->sku)) {
187 $data = $this->raw(self::FIELD_SKU);
188 if (is_null($data)) {
189 return null;
190 }
191 $this->sku = (string) $data;
192 }
193
194 return $this->sku;
195 }
196
204 public function getValue()
205 {
206 if (is_null($this->value)) {
208 $data = $this->raw(self::FIELD_VALUE);
209 if (is_null($data)) {
210 return null;
211 }
212
213 $this->value = MoneyModel::of($data);
214 }
215
216 return $this->value;
217 }
218
225 public function getCountry()
226 {
227 if (is_null($this->country)) {
229 $data = $this->raw(self::FIELD_COUNTRY);
230 if (is_null($data)) {
231 return null;
232 }
233 $this->country = (string) $data;
234 }
235
236 return $this->country;
237 }
238
245 public function getCustomerGroup()
246 {
247 if (is_null($this->customerGroup)) {
249 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
250 if (is_null($data)) {
251 return null;
252 }
253
254 $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
255 }
256
258 }
259
266 public function getChannel()
267 {
268 if (is_null($this->channel)) {
270 $data = $this->raw(self::FIELD_CHANNEL);
271 if (is_null($data)) {
272 return null;
273 }
274
275 $this->channel = ChannelResourceIdentifierModel::of($data);
276 }
277
278 return $this->channel;
279 }
280
287 public function getValidFrom()
288 {
289 if (is_null($this->validFrom)) {
291 $data = $this->raw(self::FIELD_VALID_FROM);
292 if (is_null($data)) {
293 return null;
294 }
295 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
296 if (false === $data) {
297 return null;
298 }
299 $this->validFrom = $data;
300 }
301
302 return $this->validFrom;
303 }
304
311 public function getValidUntil()
312 {
313 if (is_null($this->validUntil)) {
315 $data = $this->raw(self::FIELD_VALID_UNTIL);
316 if (is_null($data)) {
317 return null;
318 }
319 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
320 if (false === $data) {
321 return null;
322 }
323 $this->validUntil = $data;
324 }
325
326 return $this->validUntil;
327 }
328
336 public function getTiers()
337 {
338 if (is_null($this->tiers)) {
340 $data = $this->raw(self::FIELD_TIERS);
341 if (is_null($data)) {
342 return null;
343 }
344 $this->tiers = PriceTierDraftCollection::fromArray($data);
345 }
346
347 return $this->tiers;
348 }
349
356 public function getDiscounted()
357 {
358 if (is_null($this->discounted)) {
360 $data = $this->raw(self::FIELD_DISCOUNTED);
361 if (is_null($data)) {
362 return null;
363 }
364
365 $this->discounted = DiscountedPriceDraftModel::of($data);
366 }
367
368 return $this->discounted;
369 }
370
377 public function getCustom()
378 {
379 if (is_null($this->custom)) {
381 $data = $this->raw(self::FIELD_CUSTOM);
382 if (is_null($data)) {
383 return null;
384 }
385
386 $this->custom = CustomFieldsDraftModel::of($data);
387 }
388
389 return $this->custom;
390 }
391
398 public function getRecurrencePolicy()
399 {
400 if (is_null($this->recurrencePolicy)) {
402 $data = $this->raw(self::FIELD_RECURRENCE_POLICY);
403 if (is_null($data)) {
404 return null;
405 }
406
407 $this->recurrencePolicy = RecurrencePolicyResourceIdentifierModel::of($data);
408 }
409
411 }
412
419 public function getStaged()
420 {
421 if (is_null($this->staged)) {
423 $data = $this->raw(self::FIELD_STAGED);
424 if (is_null($data)) {
425 return null;
426 }
427
428 $this->staged = StagedPriceDraftModel::of($data);
429 }
430
431 return $this->staged;
432 }
433
440 public function getActive()
441 {
442 if (is_null($this->active)) {
444 $data = $this->raw(self::FIELD_ACTIVE);
445 if (is_null($data)) {
446 return null;
447 }
448 $this->active = (bool) $data;
449 }
450
451 return $this->active;
452 }
453
454
458 public function setKey(?string $key): void
459 {
460 $this->key = $key;
461 }
462
466 public function setSku(?string $sku): void
467 {
468 $this->sku = $sku;
469 }
470
474 public function setValue(?Money $value): void
475 {
476 $this->value = $value;
477 }
478
482 public function setCountry(?string $country): void
483 {
484 $this->country = $country;
485 }
486
491 {
492 $this->customerGroup = $customerGroup;
493 }
494
499 {
500 $this->channel = $channel;
501 }
502
506 public function setValidFrom(?DateTimeImmutable $validFrom): void
507 {
508 $this->validFrom = $validFrom;
509 }
510
514 public function setValidUntil(?DateTimeImmutable $validUntil): void
515 {
516 $this->validUntil = $validUntil;
517 }
518
523 {
524 $this->tiers = $tiers;
525 }
526
531 {
532 $this->discounted = $discounted;
533 }
534
538 public function setCustom(?CustomFieldsDraft $custom): void
539 {
540 $this->custom = $custom;
541 }
542
547 {
548 $this->recurrencePolicy = $recurrencePolicy;
549 }
550
554 public function setStaged(?StagedPriceDraft $staged): void
555 {
556 $this->staged = $staged;
557 }
558
562 public function setActive(?bool $active): void
563 {
564 $this->active = $active;
565 }
566
567
568 #[\ReturnTypeWillChange]
569 public function jsonSerialize()
570 {
571 $data = $this->toArray();
572 if (isset($data[StandalonePriceDraft::FIELD_VALID_FROM]) && $data[StandalonePriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
573 $data[StandalonePriceDraft::FIELD_VALID_FROM] = $data[StandalonePriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
574 }
575
576 if (isset($data[StandalonePriceDraft::FIELD_VALID_UNTIL]) && $data[StandalonePriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
577 $data[StandalonePriceDraft::FIELD_VALID_UNTIL] = $data[StandalonePriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
578 }
579 return (object) $data;
580 }
581}
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)