commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
StandalonePriceImportModel.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
106 protected $active;
107
108
112 public function __construct(
113 ?string $key = null,
114 ?string $sku = null,
115 ?TypedMoney $value = null,
116 ?string $country = null,
119 ?DateTimeImmutable $validFrom = null,
120 ?DateTimeImmutable $validUntil = null,
123 ?Custom $custom = null,
124 ?bool $active = null
125 ) {
126 $this->key = $key;
127 $this->sku = $sku;
128 $this->value = $value;
129 $this->country = $country;
130 $this->customerGroup = $customerGroup;
131 $this->channel = $channel;
132 $this->validFrom = $validFrom;
133 $this->validUntil = $validUntil;
134 $this->tiers = $tiers;
135 $this->discounted = $discounted;
136 $this->custom = $custom;
137 $this->active = $active;
138 }
139
146 public function getKey()
147 {
148 if (is_null($this->key)) {
150 $data = $this->raw(self::FIELD_KEY);
151 if (is_null($data)) {
152 return null;
153 }
154 $this->key = (string) $data;
155 }
156
157 return $this->key;
158 }
159
166 public function getSku()
167 {
168 if (is_null($this->sku)) {
170 $data = $this->raw(self::FIELD_SKU);
171 if (is_null($data)) {
172 return null;
173 }
174 $this->sku = (string) $data;
175 }
176
177 return $this->sku;
178 }
179
186 public function getValue()
187 {
188 if (is_null($this->value)) {
190 $data = $this->raw(self::FIELD_VALUE);
191 if (is_null($data)) {
192 return null;
193 }
194 $className = TypedMoneyModel::resolveDiscriminatorClass($data);
195 $this->value = $className::of($data);
196 }
197
198 return $this->value;
199 }
200
207 public function getCountry()
208 {
209 if (is_null($this->country)) {
211 $data = $this->raw(self::FIELD_COUNTRY);
212 if (is_null($data)) {
213 return null;
214 }
215 $this->country = (string) $data;
216 }
217
218 return $this->country;
219 }
220
228 public function getCustomerGroup()
229 {
230 if (is_null($this->customerGroup)) {
232 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
233 if (is_null($data)) {
234 return null;
235 }
236
237 $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
238 }
239
241 }
242
250 public function getChannel()
251 {
252 if (is_null($this->channel)) {
254 $data = $this->raw(self::FIELD_CHANNEL);
255 if (is_null($data)) {
256 return null;
257 }
258
259 $this->channel = ChannelKeyReferenceModel::of($data);
260 }
261
262 return $this->channel;
263 }
264
271 public function getValidFrom()
272 {
273 if (is_null($this->validFrom)) {
275 $data = $this->raw(self::FIELD_VALID_FROM);
276 if (is_null($data)) {
277 return null;
278 }
279 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
280 if (false === $data) {
281 return null;
282 }
283 $this->validFrom = $data;
284 }
285
286 return $this->validFrom;
287 }
288
295 public function getValidUntil()
296 {
297 if (is_null($this->validUntil)) {
299 $data = $this->raw(self::FIELD_VALID_UNTIL);
300 if (is_null($data)) {
301 return null;
302 }
303 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
304 if (false === $data) {
305 return null;
306 }
307 $this->validUntil = $data;
308 }
309
310 return $this->validUntil;
311 }
312
319 public function getTiers()
320 {
321 if (is_null($this->tiers)) {
323 $data = $this->raw(self::FIELD_TIERS);
324 if (is_null($data)) {
325 return null;
326 }
327 $this->tiers = PriceTierCollection::fromArray($data);
328 }
329
330 return $this->tiers;
331 }
332
339 public function getDiscounted()
340 {
341 if (is_null($this->discounted)) {
343 $data = $this->raw(self::FIELD_DISCOUNTED);
344 if (is_null($data)) {
345 return null;
346 }
347
348 $this->discounted = DiscountedPriceModel::of($data);
349 }
350
351 return $this->discounted;
352 }
353
360 public function getCustom()
361 {
362 if (is_null($this->custom)) {
364 $data = $this->raw(self::FIELD_CUSTOM);
365 if (is_null($data)) {
366 return null;
367 }
368
369 $this->custom = CustomModel::of($data);
370 }
371
372 return $this->custom;
373 }
374
382 public function getActive()
383 {
384 if (is_null($this->active)) {
386 $data = $this->raw(self::FIELD_ACTIVE);
387 if (is_null($data)) {
388 return null;
389 }
390 $this->active = (bool) $data;
391 }
392
393 return $this->active;
394 }
395
396
400 public function setKey(?string $key): void
401 {
402 $this->key = $key;
403 }
404
408 public function setSku(?string $sku): void
409 {
410 $this->sku = $sku;
411 }
412
416 public function setValue(?TypedMoney $value): void
417 {
418 $this->value = $value;
419 }
420
424 public function setCountry(?string $country): void
425 {
426 $this->country = $country;
427 }
428
433 {
434 $this->customerGroup = $customerGroup;
435 }
436
441 {
442 $this->channel = $channel;
443 }
444
448 public function setValidFrom(?DateTimeImmutable $validFrom): void
449 {
450 $this->validFrom = $validFrom;
451 }
452
456 public function setValidUntil(?DateTimeImmutable $validUntil): void
457 {
458 $this->validUntil = $validUntil;
459 }
460
464 public function setTiers(?PriceTierCollection $tiers): void
465 {
466 $this->tiers = $tiers;
467 }
468
473 {
474 $this->discounted = $discounted;
475 }
476
480 public function setCustom(?Custom $custom): void
481 {
482 $this->custom = $custom;
483 }
484
488 public function setActive(?bool $active): void
489 {
490 $this->active = $active;
491 }
492
493
494 #[\ReturnTypeWillChange]
495 public function jsonSerialize()
496 {
497 $data = $this->toArray();
498 if (isset($data[StandalonePriceImport::FIELD_VALID_FROM]) && $data[StandalonePriceImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
499 $data[StandalonePriceImport::FIELD_VALID_FROM] = $data[StandalonePriceImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
500 }
501
502 if (isset($data[StandalonePriceImport::FIELD_VALID_UNTIL]) && $data[StandalonePriceImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
503 $data[StandalonePriceImport::FIELD_VALID_UNTIL] = $data[StandalonePriceImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
504 }
505 return (object) $data;
506 }
507}
__construct(?string $key=null, ?string $sku=null, ?TypedMoney $value=null, ?string $country=null, ?CustomerGroupKeyReference $customerGroup=null, ?ChannelKeyReference $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?PriceTierCollection $tiers=null, ?DiscountedPrice $discounted=null, ?Custom $custom=null, ?bool $active=null)