commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
PriceImportModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
32 use DateTimeImmutable;
33 use stdClass;
34 
38 final 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 $publish;
93 
98  protected $tiers;
99 
104  protected $custom;
105 
110  protected $productVariant;
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 $publish = null,
132  ?PriceTierCollection $tiers = 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->publish = $publish;
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 
268  public function getCustomerGroup()
269  {
270  if (is_null($this->customerGroup)) {
272  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
273  if (is_null($data)) {
274  return null;
275  }
276 
277  $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
278  }
279 
280  return $this->customerGroup;
281  }
282 
290  public function getChannel()
291  {
292  if (is_null($this->channel)) {
294  $data = $this->raw(self::FIELD_CHANNEL);
295  if (is_null($data)) {
296  return null;
297  }
298 
299  $this->channel = ChannelKeyReferenceModel::of($data);
300  }
301 
302  return $this->channel;
303  }
304 
311  public function getDiscounted()
312  {
313  if (is_null($this->discounted)) {
315  $data = $this->raw(self::FIELD_DISCOUNTED);
316  if (is_null($data)) {
317  return null;
318  }
319 
320  $this->discounted = DiscountedPriceModel::of($data);
321  }
322 
323  return $this->discounted;
324  }
325 
332  public function getPublish()
333  {
334  if (is_null($this->publish)) {
336  $data = $this->raw(self::FIELD_PUBLISH);
337  if (is_null($data)) {
338  return null;
339  }
340  $this->publish = (bool) $data;
341  }
342 
343  return $this->publish;
344  }
345 
352  public function getTiers()
353  {
354  if (is_null($this->tiers)) {
356  $data = $this->raw(self::FIELD_TIERS);
357  if (is_null($data)) {
358  return null;
359  }
360  $this->tiers = PriceTierCollection::fromArray($data);
361  }
362 
363  return $this->tiers;
364  }
365 
372  public function getCustom()
373  {
374  if (is_null($this->custom)) {
376  $data = $this->raw(self::FIELD_CUSTOM);
377  if (is_null($data)) {
378  return null;
379  }
380 
381  $this->custom = CustomModel::of($data);
382  }
383 
384  return $this->custom;
385  }
386 
395  public function getProductVariant()
396  {
397  if (is_null($this->productVariant)) {
399  $data = $this->raw(self::FIELD_PRODUCT_VARIANT);
400  if (is_null($data)) {
401  return null;
402  }
403 
404  $this->productVariant = ProductVariantKeyReferenceModel::of($data);
405  }
406 
407  return $this->productVariant;
408  }
409 
418  public function getProduct()
419  {
420  if (is_null($this->product)) {
422  $data = $this->raw(self::FIELD_PRODUCT);
423  if (is_null($data)) {
424  return null;
425  }
426 
427  $this->product = ProductKeyReferenceModel::of($data);
428  }
429 
430  return $this->product;
431  }
432 
433 
437  public function setKey(?string $key): void
438  {
439  $this->key = $key;
440  }
441 
445  public function setValue(?TypedMoney $value): void
446  {
447  $this->value = $value;
448  }
449 
453  public function setCountry(?string $country): void
454  {
455  $this->country = $country;
456  }
457 
461  public function setValidFrom(?DateTimeImmutable $validFrom): void
462  {
463  $this->validFrom = $validFrom;
464  }
465 
469  public function setValidUntil(?DateTimeImmutable $validUntil): void
470  {
471  $this->validUntil = $validUntil;
472  }
473 
478  {
479  $this->customerGroup = $customerGroup;
480  }
481 
485  public function setChannel(?ChannelKeyReference $channel): void
486  {
487  $this->channel = $channel;
488  }
489 
493  public function setDiscounted(?DiscountedPrice $discounted): void
494  {
495  $this->discounted = $discounted;
496  }
497 
501  public function setPublish(?bool $publish): void
502  {
503  $this->publish = $publish;
504  }
505 
509  public function setTiers(?PriceTierCollection $tiers): void
510  {
511  $this->tiers = $tiers;
512  }
513 
517  public function setCustom(?Custom $custom): void
518  {
519  $this->custom = $custom;
520  }
521 
526  {
527  $this->productVariant = $productVariant;
528  }
529 
533  public function setProduct(?ProductKeyReference $product): void
534  {
535  $this->product = $product;
536  }
537 
538 
539  #[\ReturnTypeWillChange]
540  public function jsonSerialize()
541  {
542  $data = $this->toArray();
543  if (isset($data[PriceImport::FIELD_VALID_FROM]) && $data[PriceImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
544  $data[PriceImport::FIELD_VALID_FROM] = $data[PriceImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
545  }
546 
547  if (isset($data[PriceImport::FIELD_VALID_UNTIL]) && $data[PriceImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
548  $data[PriceImport::FIELD_VALID_UNTIL] = $data[PriceImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
549  }
550  return (object) $data;
551  }
552 }
__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 $publish=null, ?PriceTierCollection $tiers=null, ?Custom $custom=null, ?ProductVariantKeyReference $productVariant=null, ?ProductKeyReference $product=null)
setCustomerGroup(?CustomerGroupKeyReference $customerGroup)
setProductVariant(?ProductVariantKeyReference $productVariant)