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
26use DateTimeImmutable;
27use stdClass;
28
33{
38 protected $key;
39
44 protected $sku;
45
50 protected $value;
51
56 protected $country;
57
62 protected $customerGroup;
63
68 protected $channel;
69
74 protected $validFrom;
75
80 protected $validUntil;
81
86 protected $tiers;
87
92 protected $discounted;
93
98 protected $custom;
99
104 protected $staged;
105
110 protected $active;
111
112
116 public function __construct(
117 ?string $key = null,
118 ?string $sku = null,
119 ?Money $value = null,
120 ?string $country = null,
123 ?DateTimeImmutable $validFrom = null,
124 ?DateTimeImmutable $validUntil = null,
129 ?bool $active = null
130 ) {
131 $this->key = $key;
132 $this->sku = $sku;
133 $this->value = $value;
134 $this->country = $country;
135 $this->customerGroup = $customerGroup;
136 $this->channel = $channel;
137 $this->validFrom = $validFrom;
138 $this->validUntil = $validUntil;
139 $this->tiers = $tiers;
140 $this->discounted = $discounted;
141 $this->custom = $custom;
142 $this->staged = $staged;
143 $this->active = $active;
144 }
145
152 public function getKey()
153 {
154 if (is_null($this->key)) {
156 $data = $this->raw(self::FIELD_KEY);
157 if (is_null($data)) {
158 return null;
159 }
160 $this->key = (string) $data;
161 }
162
163 return $this->key;
164 }
165
173 public function getSku()
174 {
175 if (is_null($this->sku)) {
177 $data = $this->raw(self::FIELD_SKU);
178 if (is_null($data)) {
179 return null;
180 }
181 $this->sku = (string) $data;
182 }
183
184 return $this->sku;
185 }
186
194 public function getValue()
195 {
196 if (is_null($this->value)) {
198 $data = $this->raw(self::FIELD_VALUE);
199 if (is_null($data)) {
200 return null;
201 }
202
203 $this->value = MoneyModel::of($data);
204 }
205
206 return $this->value;
207 }
208
215 public function getCountry()
216 {
217 if (is_null($this->country)) {
219 $data = $this->raw(self::FIELD_COUNTRY);
220 if (is_null($data)) {
221 return null;
222 }
223 $this->country = (string) $data;
224 }
225
226 return $this->country;
227 }
228
235 public function getCustomerGroup()
236 {
237 if (is_null($this->customerGroup)) {
239 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
240 if (is_null($data)) {
241 return null;
242 }
243
244 $this->customerGroup = CustomerGroupResourceIdentifierModel::of($data);
245 }
246
248 }
249
256 public function getChannel()
257 {
258 if (is_null($this->channel)) {
260 $data = $this->raw(self::FIELD_CHANNEL);
261 if (is_null($data)) {
262 return null;
263 }
264
265 $this->channel = ChannelResourceIdentifierModel::of($data);
266 }
267
268 return $this->channel;
269 }
270
277 public function getValidFrom()
278 {
279 if (is_null($this->validFrom)) {
281 $data = $this->raw(self::FIELD_VALID_FROM);
282 if (is_null($data)) {
283 return null;
284 }
285 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
286 if (false === $data) {
287 return null;
288 }
289 $this->validFrom = $data;
290 }
291
292 return $this->validFrom;
293 }
294
301 public function getValidUntil()
302 {
303 if (is_null($this->validUntil)) {
305 $data = $this->raw(self::FIELD_VALID_UNTIL);
306 if (is_null($data)) {
307 return null;
308 }
309 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
310 if (false === $data) {
311 return null;
312 }
313 $this->validUntil = $data;
314 }
315
316 return $this->validUntil;
317 }
318
326 public function getTiers()
327 {
328 if (is_null($this->tiers)) {
330 $data = $this->raw(self::FIELD_TIERS);
331 if (is_null($data)) {
332 return null;
333 }
334 $this->tiers = PriceTierDraftCollection::fromArray($data);
335 }
336
337 return $this->tiers;
338 }
339
346 public function getDiscounted()
347 {
348 if (is_null($this->discounted)) {
350 $data = $this->raw(self::FIELD_DISCOUNTED);
351 if (is_null($data)) {
352 return null;
353 }
354
355 $this->discounted = DiscountedPriceDraftModel::of($data);
356 }
357
358 return $this->discounted;
359 }
360
367 public function getCustom()
368 {
369 if (is_null($this->custom)) {
371 $data = $this->raw(self::FIELD_CUSTOM);
372 if (is_null($data)) {
373 return null;
374 }
375
376 $this->custom = CustomFieldsDraftModel::of($data);
377 }
378
379 return $this->custom;
380 }
381
388 public function getStaged()
389 {
390 if (is_null($this->staged)) {
392 $data = $this->raw(self::FIELD_STAGED);
393 if (is_null($data)) {
394 return null;
395 }
396
397 $this->staged = StagedPriceDraftModel::of($data);
398 }
399
400 return $this->staged;
401 }
402
409 public function getActive()
410 {
411 if (is_null($this->active)) {
413 $data = $this->raw(self::FIELD_ACTIVE);
414 if (is_null($data)) {
415 return null;
416 }
417 $this->active = (bool) $data;
418 }
419
420 return $this->active;
421 }
422
423
427 public function setKey(?string $key): void
428 {
429 $this->key = $key;
430 }
431
435 public function setSku(?string $sku): void
436 {
437 $this->sku = $sku;
438 }
439
443 public function setValue(?Money $value): void
444 {
445 $this->value = $value;
446 }
447
451 public function setCountry(?string $country): void
452 {
453 $this->country = $country;
454 }
455
460 {
461 $this->customerGroup = $customerGroup;
462 }
463
468 {
469 $this->channel = $channel;
470 }
471
475 public function setValidFrom(?DateTimeImmutable $validFrom): void
476 {
477 $this->validFrom = $validFrom;
478 }
479
483 public function setValidUntil(?DateTimeImmutable $validUntil): void
484 {
485 $this->validUntil = $validUntil;
486 }
487
492 {
493 $this->tiers = $tiers;
494 }
495
500 {
501 $this->discounted = $discounted;
502 }
503
507 public function setCustom(?CustomFieldsDraft $custom): void
508 {
509 $this->custom = $custom;
510 }
511
515 public function setStaged(?StagedPriceDraft $staged): void
516 {
517 $this->staged = $staged;
518 }
519
523 public function setActive(?bool $active): void
524 {
525 $this->active = $active;
526 }
527
528
529 #[\ReturnTypeWillChange]
530 public function jsonSerialize()
531 {
532 $data = $this->toArray();
533 if (isset($data[StandalonePriceDraft::FIELD_VALID_FROM]) && $data[StandalonePriceDraft::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
534 $data[StandalonePriceDraft::FIELD_VALID_FROM] = $data[StandalonePriceDraft::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
535 }
536
537 if (isset($data[StandalonePriceDraft::FIELD_VALID_UNTIL]) && $data[StandalonePriceDraft::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
538 $data[StandalonePriceDraft::FIELD_VALID_UNTIL] = $data[StandalonePriceDraft::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
539 }
540 return (object) $data;
541 }
542}
__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, ?StagedPriceDraft $staged=null, ?bool $active=null)