commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
PriceImportModel.php
1<?php
2
3declare(strict_types=1);
10
32use DateTimeImmutable;
33use stdClass;
34
38final class PriceImportModel extends JsonObjectModel implements PriceImport
39{
44 protected $key;
45
50 protected $value;
51
56 protected $country;
57
62 protected $validFrom;
63
68 protected $validUntil;
69
74 protected $customerGroup;
75
80 protected $channel;
81
86 protected $discounted;
87
92 protected $staged;
93
98 protected $tiers;
99
104 protected $custom;
105
111
116 protected $product;
117
118
122 public function __construct(
123 ?string $key = null,
124 ?TypedMoney $value = null,
125 ?string $country = null,
126 ?DateTimeImmutable $validFrom = null,
127 ?DateTimeImmutable $validUntil = null,
131 ?bool $staged = null,
133 ?Custom $custom = null,
136 ) {
137 $this->key = $key;
138 $this->value = $value;
139 $this->country = $country;
140 $this->validFrom = $validFrom;
141 $this->validUntil = $validUntil;
142 $this->customerGroup = $customerGroup;
143 $this->channel = $channel;
144 $this->discounted = $discounted;
145 $this->staged = $staged;
146 $this->tiers = $tiers;
147 $this->custom = $custom;
148 $this->productVariant = $productVariant;
149 $this->product = $product;
150 }
151
158 public function getKey()
159 {
160 if (is_null($this->key)) {
162 $data = $this->raw(self::FIELD_KEY);
163 if (is_null($data)) {
164 return null;
165 }
166 $this->key = (string) $data;
167 }
168
169 return $this->key;
170 }
171
178 public function getValue()
179 {
180 if (is_null($this->value)) {
182 $data = $this->raw(self::FIELD_VALUE);
183 if (is_null($data)) {
184 return null;
185 }
186 $className = TypedMoneyModel::resolveDiscriminatorClass($data);
187 $this->value = $className::of($data);
188 }
189
190 return $this->value;
191 }
192
199 public function getCountry()
200 {
201 if (is_null($this->country)) {
203 $data = $this->raw(self::FIELD_COUNTRY);
204 if (is_null($data)) {
205 return null;
206 }
207 $this->country = (string) $data;
208 }
209
210 return $this->country;
211 }
212
219 public function getValidFrom()
220 {
221 if (is_null($this->validFrom)) {
223 $data = $this->raw(self::FIELD_VALID_FROM);
224 if (is_null($data)) {
225 return null;
226 }
227 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
228 if (false === $data) {
229 return null;
230 }
231 $this->validFrom = $data;
232 }
233
234 return $this->validFrom;
235 }
236
243 public function getValidUntil()
244 {
245 if (is_null($this->validUntil)) {
247 $data = $this->raw(self::FIELD_VALID_UNTIL);
248 if (is_null($data)) {
249 return null;
250 }
251 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
252 if (false === $data) {
253 return null;
254 }
255 $this->validUntil = $data;
256 }
257
258 return $this->validUntil;
259 }
260
267 public function getCustomerGroup()
268 {
269 if (is_null($this->customerGroup)) {
271 $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
272 if (is_null($data)) {
273 return null;
274 }
275
276 $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
277 }
278
280 }
281
288 public function getChannel()
289 {
290 if (is_null($this->channel)) {
292 $data = $this->raw(self::FIELD_CHANNEL);
293 if (is_null($data)) {
294 return null;
295 }
296
297 $this->channel = ChannelKeyReferenceModel::of($data);
298 }
299
300 return $this->channel;
301 }
302
309 public function getDiscounted()
310 {
311 if (is_null($this->discounted)) {
313 $data = $this->raw(self::FIELD_DISCOUNTED);
314 if (is_null($data)) {
315 return null;
316 }
317
318 $this->discounted = DiscountedPriceModel::of($data);
319 }
320
321 return $this->discounted;
322 }
323
333 public function getStaged()
334 {
335 if (is_null($this->staged)) {
337 $data = $this->raw(self::FIELD_STAGED);
338 if (is_null($data)) {
339 return null;
340 }
341 $this->staged = (bool) $data;
342 }
343
344 return $this->staged;
345 }
346
353 public function getTiers()
354 {
355 if (is_null($this->tiers)) {
357 $data = $this->raw(self::FIELD_TIERS);
358 if (is_null($data)) {
359 return null;
360 }
361 $this->tiers = PriceTierCollection::fromArray($data);
362 }
363
364 return $this->tiers;
365 }
366
373 public function getCustom()
374 {
375 if (is_null($this->custom)) {
377 $data = $this->raw(self::FIELD_CUSTOM);
378 if (is_null($data)) {
379 return null;
380 }
381
382 $this->custom = CustomModel::of($data);
383 }
384
385 return $this->custom;
386 }
387
394 public function getProductVariant()
395 {
396 if (is_null($this->productVariant)) {
398 $data = $this->raw(self::FIELD_PRODUCT_VARIANT);
399 if (is_null($data)) {
400 return null;
401 }
402
403 $this->productVariant = ProductVariantKeyReferenceModel::of($data);
404 }
405
407 }
408
415 public function getProduct()
416 {
417 if (is_null($this->product)) {
419 $data = $this->raw(self::FIELD_PRODUCT);
420 if (is_null($data)) {
421 return null;
422 }
423
424 $this->product = ProductKeyReferenceModel::of($data);
425 }
426
427 return $this->product;
428 }
429
430
434 public function setKey(?string $key): void
435 {
436 $this->key = $key;
437 }
438
442 public function setValue(?TypedMoney $value): void
443 {
444 $this->value = $value;
445 }
446
450 public function setCountry(?string $country): void
451 {
452 $this->country = $country;
453 }
454
458 public function setValidFrom(?DateTimeImmutable $validFrom): void
459 {
460 $this->validFrom = $validFrom;
461 }
462
466 public function setValidUntil(?DateTimeImmutable $validUntil): void
467 {
468 $this->validUntil = $validUntil;
469 }
470
475 {
476 $this->customerGroup = $customerGroup;
477 }
478
483 {
484 $this->channel = $channel;
485 }
486
491 {
492 $this->discounted = $discounted;
493 }
494
498 public function setStaged(?bool $staged): void
499 {
500 $this->staged = $staged;
501 }
502
506 public function setTiers(?PriceTierCollection $tiers): void
507 {
508 $this->tiers = $tiers;
509 }
510
514 public function setCustom(?Custom $custom): void
515 {
516 $this->custom = $custom;
517 }
518
523 {
524 $this->productVariant = $productVariant;
525 }
526
531 {
532 $this->product = $product;
533 }
534
535
536 #[\ReturnTypeWillChange]
537 public function jsonSerialize()
538 {
539 $data = $this->toArray();
540 if (isset($data[PriceImport::FIELD_VALID_FROM]) && $data[PriceImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
541 $data[PriceImport::FIELD_VALID_FROM] = $data[PriceImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
542 }
543
544 if (isset($data[PriceImport::FIELD_VALID_UNTIL]) && $data[PriceImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
545 $data[PriceImport::FIELD_VALID_UNTIL] = $data[PriceImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
546 }
547 return (object) $data;
548 }
549}
__construct(?string $key=null, ?TypedMoney $value=null, ?string $country=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?CustomerGroupKeyReference $customerGroup=null, ?ChannelKeyReference $channel=null, ?DiscountedPrice $discounted=null, ?bool $staged=null, ?PriceTierCollection $tiers=null, ?Custom $custom=null, ?ProductVariantKeyReference $productVariant=null, ?ProductKeyReference $product=null)
setCustomerGroup(?CustomerGroupKeyReference $customerGroup)
setProductVariant(?ProductVariantKeyReference $productVariant)