commercetools-sdk-php-v2
The commercetools platform, import-api and 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 $staged;
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 $staged = 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->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 
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 
335  public function getStaged()
336  {
337  if (is_null($this->staged)) {
339  $data = $this->raw(self::FIELD_STAGED);
340  if (is_null($data)) {
341  return null;
342  }
343  $this->staged = (bool) $data;
344  }
345 
346  return $this->staged;
347  }
348 
355  public function getTiers()
356  {
357  if (is_null($this->tiers)) {
359  $data = $this->raw(self::FIELD_TIERS);
360  if (is_null($data)) {
361  return null;
362  }
363  $this->tiers = PriceTierCollection::fromArray($data);
364  }
365 
366  return $this->tiers;
367  }
368 
375  public function getCustom()
376  {
377  if (is_null($this->custom)) {
379  $data = $this->raw(self::FIELD_CUSTOM);
380  if (is_null($data)) {
381  return null;
382  }
383 
384  $this->custom = CustomModel::of($data);
385  }
386 
387  return $this->custom;
388  }
389 
398  public function getProductVariant()
399  {
400  if (is_null($this->productVariant)) {
402  $data = $this->raw(self::FIELD_PRODUCT_VARIANT);
403  if (is_null($data)) {
404  return null;
405  }
406 
407  $this->productVariant = ProductVariantKeyReferenceModel::of($data);
408  }
409 
410  return $this->productVariant;
411  }
412 
421  public function getProduct()
422  {
423  if (is_null($this->product)) {
425  $data = $this->raw(self::FIELD_PRODUCT);
426  if (is_null($data)) {
427  return null;
428  }
429 
430  $this->product = ProductKeyReferenceModel::of($data);
431  }
432 
433  return $this->product;
434  }
435 
436 
440  public function setKey(?string $key): void
441  {
442  $this->key = $key;
443  }
444 
448  public function setValue(?TypedMoney $value): void
449  {
450  $this->value = $value;
451  }
452 
456  public function setCountry(?string $country): void
457  {
458  $this->country = $country;
459  }
460 
464  public function setValidFrom(?DateTimeImmutable $validFrom): void
465  {
466  $this->validFrom = $validFrom;
467  }
468 
472  public function setValidUntil(?DateTimeImmutable $validUntil): void
473  {
474  $this->validUntil = $validUntil;
475  }
476 
481  {
482  $this->customerGroup = $customerGroup;
483  }
484 
488  public function setChannel(?ChannelKeyReference $channel): void
489  {
490  $this->channel = $channel;
491  }
492 
496  public function setDiscounted(?DiscountedPrice $discounted): void
497  {
498  $this->discounted = $discounted;
499  }
500 
504  public function setStaged(?bool $staged): void
505  {
506  $this->staged = $staged;
507  }
508 
512  public function setTiers(?PriceTierCollection $tiers): void
513  {
514  $this->tiers = $tiers;
515  }
516 
520  public function setCustom(?Custom $custom): void
521  {
522  $this->custom = $custom;
523  }
524 
529  {
530  $this->productVariant = $productVariant;
531  }
532 
536  public function setProduct(?ProductKeyReference $product): void
537  {
538  $this->product = $product;
539  }
540 
541 
542  #[\ReturnTypeWillChange]
543  public function jsonSerialize()
544  {
545  $data = $this->toArray();
546  if (isset($data[PriceImport::FIELD_VALID_FROM]) && $data[PriceImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
547  $data[PriceImport::FIELD_VALID_FROM] = $data[PriceImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
548  }
549 
550  if (isset($data[PriceImport::FIELD_VALID_UNTIL]) && $data[PriceImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
551  $data[PriceImport::FIELD_VALID_UNTIL] = $data[PriceImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
552  }
553  return (object) $data;
554  }
555 }
__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)