commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
StandalonePriceImportModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
28 use DateTimeImmutable;
29 use 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 
102 
106  public function __construct(
107  ?string $key = null,
108  ?string $sku = null,
109  ?TypedMoney $value = null,
110  ?string $country = null,
113  ?DateTimeImmutable $validFrom = null,
114  ?DateTimeImmutable $validUntil = null,
115  ?PriceTierCollection $tiers = null,
117  ?Custom $custom = null
118  ) {
119  $this->key = $key;
120  $this->sku = $sku;
121  $this->value = $value;
122  $this->country = $country;
123  $this->customerGroup = $customerGroup;
124  $this->channel = $channel;
125  $this->validFrom = $validFrom;
126  $this->validUntil = $validUntil;
127  $this->tiers = $tiers;
128  $this->discounted = $discounted;
129  $this->custom = $custom;
130  }
131 
138  public function getKey()
139  {
140  if (is_null($this->key)) {
142  $data = $this->raw(self::FIELD_KEY);
143  if (is_null($data)) {
144  return null;
145  }
146  $this->key = (string) $data;
147  }
148 
149  return $this->key;
150  }
151 
158  public function getSku()
159  {
160  if (is_null($this->sku)) {
162  $data = $this->raw(self::FIELD_SKU);
163  if (is_null($data)) {
164  return null;
165  }
166  $this->sku = (string) $data;
167  }
168 
169  return $this->sku;
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 getCustomerGroup()
220  {
221  if (is_null($this->customerGroup)) {
223  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
224  if (is_null($data)) {
225  return null;
226  }
227 
228  $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
229  }
230 
231  return $this->customerGroup;
232  }
233 
240  public function getChannel()
241  {
242  if (is_null($this->channel)) {
244  $data = $this->raw(self::FIELD_CHANNEL);
245  if (is_null($data)) {
246  return null;
247  }
248 
249  $this->channel = ChannelKeyReferenceModel::of($data);
250  }
251 
252  return $this->channel;
253  }
254 
261  public function getValidFrom()
262  {
263  if (is_null($this->validFrom)) {
265  $data = $this->raw(self::FIELD_VALID_FROM);
266  if (is_null($data)) {
267  return null;
268  }
269  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
270  if (false === $data) {
271  return null;
272  }
273  $this->validFrom = $data;
274  }
275 
276  return $this->validFrom;
277  }
278 
285  public function getValidUntil()
286  {
287  if (is_null($this->validUntil)) {
289  $data = $this->raw(self::FIELD_VALID_UNTIL);
290  if (is_null($data)) {
291  return null;
292  }
293  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
294  if (false === $data) {
295  return null;
296  }
297  $this->validUntil = $data;
298  }
299 
300  return $this->validUntil;
301  }
302 
309  public function getTiers()
310  {
311  if (is_null($this->tiers)) {
313  $data = $this->raw(self::FIELD_TIERS);
314  if (is_null($data)) {
315  return null;
316  }
317  $this->tiers = PriceTierCollection::fromArray($data);
318  }
319 
320  return $this->tiers;
321  }
322 
329  public function getDiscounted()
330  {
331  if (is_null($this->discounted)) {
333  $data = $this->raw(self::FIELD_DISCOUNTED);
334  if (is_null($data)) {
335  return null;
336  }
337 
338  $this->discounted = DiscountedPriceModel::of($data);
339  }
340 
341  return $this->discounted;
342  }
343 
350  public function getCustom()
351  {
352  if (is_null($this->custom)) {
354  $data = $this->raw(self::FIELD_CUSTOM);
355  if (is_null($data)) {
356  return null;
357  }
358 
359  $this->custom = CustomModel::of($data);
360  }
361 
362  return $this->custom;
363  }
364 
365 
369  public function setKey(?string $key): void
370  {
371  $this->key = $key;
372  }
373 
377  public function setSku(?string $sku): void
378  {
379  $this->sku = $sku;
380  }
381 
385  public function setValue(?TypedMoney $value): void
386  {
387  $this->value = $value;
388  }
389 
393  public function setCountry(?string $country): void
394  {
395  $this->country = $country;
396  }
397 
402  {
403  $this->customerGroup = $customerGroup;
404  }
405 
409  public function setChannel(?ChannelKeyReference $channel): void
410  {
411  $this->channel = $channel;
412  }
413 
417  public function setValidFrom(?DateTimeImmutable $validFrom): void
418  {
419  $this->validFrom = $validFrom;
420  }
421 
425  public function setValidUntil(?DateTimeImmutable $validUntil): void
426  {
427  $this->validUntil = $validUntil;
428  }
429 
433  public function setTiers(?PriceTierCollection $tiers): void
434  {
435  $this->tiers = $tiers;
436  }
437 
441  public function setDiscounted(?DiscountedPrice $discounted): void
442  {
443  $this->discounted = $discounted;
444  }
445 
449  public function setCustom(?Custom $custom): void
450  {
451  $this->custom = $custom;
452  }
453 
454 
455  #[\ReturnTypeWillChange]
456  public function jsonSerialize()
457  {
458  $data = $this->toArray();
459  if (isset($data[StandalonePriceImport::FIELD_VALID_FROM]) && $data[StandalonePriceImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
460  $data[StandalonePriceImport::FIELD_VALID_FROM] = $data[StandalonePriceImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
461  }
462 
463  if (isset($data[StandalonePriceImport::FIELD_VALID_UNTIL]) && $data[StandalonePriceImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
464  $data[StandalonePriceImport::FIELD_VALID_UNTIL] = $data[StandalonePriceImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
465  }
466  return (object) $data;
467  }
468 }
__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)