commercetools-sdk-php-v2
The commercetools platform, import-api and 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 
200  public function getCountry()
201  {
202  if (is_null($this->country)) {
204  $data = $this->raw(self::FIELD_COUNTRY);
205  if (is_null($data)) {
206  return null;
207  }
208  $this->country = (string) $data;
209  }
210 
211  return $this->country;
212  }
213 
221  public function getCustomerGroup()
222  {
223  if (is_null($this->customerGroup)) {
225  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
226  if (is_null($data)) {
227  return null;
228  }
229 
230  $this->customerGroup = CustomerGroupKeyReferenceModel::of($data);
231  }
232 
233  return $this->customerGroup;
234  }
235 
243  public function getChannel()
244  {
245  if (is_null($this->channel)) {
247  $data = $this->raw(self::FIELD_CHANNEL);
248  if (is_null($data)) {
249  return null;
250  }
251 
252  $this->channel = ChannelKeyReferenceModel::of($data);
253  }
254 
255  return $this->channel;
256  }
257 
264  public function getValidFrom()
265  {
266  if (is_null($this->validFrom)) {
268  $data = $this->raw(self::FIELD_VALID_FROM);
269  if (is_null($data)) {
270  return null;
271  }
272  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
273  if (false === $data) {
274  return null;
275  }
276  $this->validFrom = $data;
277  }
278 
279  return $this->validFrom;
280  }
281 
288  public function getValidUntil()
289  {
290  if (is_null($this->validUntil)) {
292  $data = $this->raw(self::FIELD_VALID_UNTIL);
293  if (is_null($data)) {
294  return null;
295  }
296  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
297  if (false === $data) {
298  return null;
299  }
300  $this->validUntil = $data;
301  }
302 
303  return $this->validUntil;
304  }
305 
312  public function getTiers()
313  {
314  if (is_null($this->tiers)) {
316  $data = $this->raw(self::FIELD_TIERS);
317  if (is_null($data)) {
318  return null;
319  }
320  $this->tiers = PriceTierCollection::fromArray($data);
321  }
322 
323  return $this->tiers;
324  }
325 
332  public function getDiscounted()
333  {
334  if (is_null($this->discounted)) {
336  $data = $this->raw(self::FIELD_DISCOUNTED);
337  if (is_null($data)) {
338  return null;
339  }
340 
341  $this->discounted = DiscountedPriceModel::of($data);
342  }
343 
344  return $this->discounted;
345  }
346 
353  public function getCustom()
354  {
355  if (is_null($this->custom)) {
357  $data = $this->raw(self::FIELD_CUSTOM);
358  if (is_null($data)) {
359  return null;
360  }
361 
362  $this->custom = CustomModel::of($data);
363  }
364 
365  return $this->custom;
366  }
367 
368 
372  public function setKey(?string $key): void
373  {
374  $this->key = $key;
375  }
376 
380  public function setSku(?string $sku): void
381  {
382  $this->sku = $sku;
383  }
384 
388  public function setValue(?TypedMoney $value): void
389  {
390  $this->value = $value;
391  }
392 
396  public function setCountry(?string $country): void
397  {
398  $this->country = $country;
399  }
400 
405  {
406  $this->customerGroup = $customerGroup;
407  }
408 
412  public function setChannel(?ChannelKeyReference $channel): void
413  {
414  $this->channel = $channel;
415  }
416 
420  public function setValidFrom(?DateTimeImmutable $validFrom): void
421  {
422  $this->validFrom = $validFrom;
423  }
424 
428  public function setValidUntil(?DateTimeImmutable $validUntil): void
429  {
430  $this->validUntil = $validUntil;
431  }
432 
436  public function setTiers(?PriceTierCollection $tiers): void
437  {
438  $this->tiers = $tiers;
439  }
440 
444  public function setDiscounted(?DiscountedPrice $discounted): void
445  {
446  $this->discounted = $discounted;
447  }
448 
452  public function setCustom(?Custom $custom): void
453  {
454  $this->custom = $custom;
455  }
456 
457 
458  #[\ReturnTypeWillChange]
459  public function jsonSerialize()
460  {
461  $data = $this->toArray();
462  if (isset($data[StandalonePriceImport::FIELD_VALID_FROM]) && $data[StandalonePriceImport::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
463  $data[StandalonePriceImport::FIELD_VALID_FROM] = $data[StandalonePriceImport::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
464  }
465 
466  if (isset($data[StandalonePriceImport::FIELD_VALID_UNTIL]) && $data[StandalonePriceImport::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
467  $data[StandalonePriceImport::FIELD_VALID_UNTIL] = $data[StandalonePriceImport::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
468  }
469  return (object) $data;
470  }
471 }
__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)